Guest User

Untitled

a guest
Jul 27th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         TT for 2ch
  3. // @version      1
  4. // @description  Adds quick TT button for 2ch
  5. // @author       (You)
  6. // @match        https://www.2ch.hk/*
  7. // @match        https://*.2ch.hk/*
  8. // @match        https://2ch.hk/*
  9. // @match        https://www.2ch.pm/*
  10. // @match        https://*.2ch.pm/*
  11. // @match        https://2ch.pm/*
  12. // @grant        none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16.     'use strict';
  17.  
  18.     function render() {
  19.         var i, href, match, articles = document.querySelectorAll('a[download]:not(.ttFinalised)');
  20.         if (!articles) return;
  21.  
  22.         for(i = 0; i < articles.length; i++) {
  23.             if (match = articles[i].parentNode.innerHTML.match(/6\d{18}/g)) {
  24.                 href = document.createElement("a"); href.target = "_blank";
  25.                 href.href = `https://www.tiktok.com/share/video/${match[0]}`;
  26.                 href.innerHTML = "» TikTok «";
  27.  
  28.                 articles[i]
  29.                     .parentNode
  30.                     .appendChild(href);
  31.             }
  32.             articles[i].classList.add("ttFinalised");
  33.         }
  34.     }
  35.     const root = document.getElementsByClassName("thread")[0];
  36.     const threadObserver = new MutationObserver(render);
  37.     render();
  38.  
  39.     threadObserver.observe(root, {
  40.         childList: true,
  41.         subtree: true,
  42.         attributes: false
  43.     });
  44. })();
Add Comment
Please, Sign In to add comment