tglinks.js 888 B

123456789101112131415161718192021222324
  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. newHtmlStr = newHtmlStr.replace('if\s*\(true\)\s*\{', 'if (false) {');
  17. html = newHtmlStr;
  18. }
  19. $.done({
  20. body: html
  21. });