tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

disqus-embed.js (1453B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 /* globals browser, embedHelperLib */
      6 
      7 if (!window.smartblockDisqusShimInitialized) {
      8  // Guard against this script running multiple times
      9  window.smartblockDisqusShimInitialized = true;
     10 
     11  /**
     12   * Finds a Disqus embed script URL in the document. Validates that
     13   * the URL matches https://*.disqus.com/embed.js format.
     14   *
     15   * @returns {string|undefined} The script URL if found, undefined otherwise.
     16   */
     17  function getDisqusEmbedScriptURL() {
     18    for (const script of document.querySelectorAll("script[src]")) {
     19      try {
     20        const url = new URL(script.src);
     21        if (
     22          url.protocol === "https:" &&
     23          url.hostname.endsWith(".disqus.com") &&
     24          url.pathname === "/embed.js"
     25        ) {
     26          return url.href;
     27        }
     28      } catch {
     29        // Invalid URL, skip
     30      }
     31    }
     32    return undefined;
     33  }
     34 
     35  // Get the script URL from the page. We can't hardcode it because the
     36  // subdomain is site specific.
     37  const scriptURL = getDisqusEmbedScriptURL();
     38  if (scriptURL) {
     39    embedHelperLib.initEmbedShim({
     40      shimId: "DisqusEmbed",
     41      scriptURL,
     42      embedLogoURL: "https://smartblock.firefox.etp/disqus.svg",
     43      embedSelector: "#disqus_thread",
     44      isTestShim: false,
     45    });
     46  }
     47 }