tglinks.js 751 B

123456789101112131415161718192021
  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. // 定义新的href和链接文本
  10. let newHref = originalHref.replace('tg://', 'ncg://');
  11. let newText = 'View on Nicegram';
  12. let replacement = `<a class="tgme_action_button_new shine" href="${newHref}">${newText}</a>`;
  13. let newHtmlStr = html.replace(regex, matches[0]+'\n'+replacement);
  14. html = newHtmlStr;
  15. }
  16. $.done({
  17. body: html
  18. });