tglinks.js 1006 B

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