tglinks.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. let html = $response.body || '';
  2. let regex = /<a class="tgme_action_button_new shine" href="([^"]+)">([^<]+)<\/a>/;
  3. console.log("###tglinks###");
  4. let regex = /<div class="tgme_page_action">\s*<a class="tgme_action_button_new shine" href="([^"]+)">([^<]+)<\/a>\s*<\/div>/;
  5. let matches = html.match(regex);
  6. if (matches) {
  7. let allContent = matches[0];
  8. let originalHref = matches[1];
  9. let originalText = matches[2];
  10. console.log(originalHref);
  11. console.log(originalText);
  12. // 定义新的href和链接文本
  13. let newHref = originalHref.replace('tg://', 'ncg://');
  14. let newText = 'View on Nicegram';
  15. let replacement = `<a class="tgme_action_button_new shine" href="${newHref}">${newText}</a>`;
  16. let newHtmlStr = html.replace(regex, matches[0]+'\n'+replacement);
  17. let regex2 = /var\s*protoUrl\s*=\s*"([^"]+)"/;
  18. newHtmlStr = newHtmlStr.replace(regex, 'var protoUrl=null');
  19. newHtmlStr = newHtmlStr.replace('if\s*\(true\)\s*\{', 'if (false) {');
  20. html = newHtmlStr;
  21. }
  22. $.done({
  23. body: html
  24. });