quotelinkify quotes of postIDs

run this script before 4chan-x to allow quotes of postIDs that "look like quotelinks" to become real quotelinks, set 4chan-x to load on document-end

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        quotelinkify quotes of postIDs
// @namespace   Violentmonkey Scripts
// @match       https://boards.4chan.org/*
// @grant       none
// @version     1.2
// @author      justrunmyscripts
// @description run this script before 4chan-x to allow quotes of postIDs that "look like quotelinks" to become real quotelinks, set 4chan-x to load on document-end
// @run-at      document-end
// @license     MIT
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// ==/UserScript==

// const thread = document.getElementsByClassName('thread')[0];
// const disconnect = VM.observe(thread, () => { // failed attempt

  console.log('running quotelinkify...')

  const all_quotes = document.getElementsByClassName("quote");

  const quoteLinkify = (quote_element) => {
    const post_id = quote_element.innerText.match(/\d+/)[0];

    const new_element = document.createElement("a");
    new_element.href = `#p${post_id}`;
    new_element.innerHTML = `>${post_id}`;
    new_element.className = "quotelink";

    quote_element.replaceWith(new_element);
  };

  // reverse iteration since we are replacing elements as we go
  for (let i = all_quotes.length - 1; i > 0; i--) {
    let quote = all_quotes[i];
    if (quote.innerText.match(/>\d+$/)) {
      quoteLinkify(quote);
    }
  }

// }); // failed attempt