fxzhihu-script

fix up zhihu in your browser.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         fxzhihu-script
// @namespace    https://thynanami.dev
// @version      0.1.4
// @author       Nanami Nakano
// @description  fix up zhihu in your browser.
// @license      MIT
// @match        https://www.zhihu.com/question/*
// @match        https://www.zhihu.com/question/*/answer/*
// @match        https://zhuanlan.zhihu.com/p/*
// @match        https://www.zhihu.com/pin/*
// @match        https://www.google.com/search*
// ==/UserScript==

(function () {
  'use strict';

  const href = window.location.href;
  if (href.includes("google")) {
    let links = document.querySelectorAll('a[rel="noopener"]');
    if (links.length == 0) {
      links = document.querySelectorAll('a[role="presentation"]');
    }
    links.forEach((link) => {
      var _a;
      const linkHref = link.getAttribute("href") || "";
      if (linkHref.includes("www.zhihu.com/question") || linkHref.includes("zhuanlan.zhihu.com/p") || linkHref.includes("zhihu.com/pin")) {
        link.setAttribute("href", linkHref.replace("zhihu.com", "fxzhihu.com"));
        const cite = link.querySelector("div > div > div > div > cite") || link.querySelector('span[role="text"]');
        if (cite) {
          cite.textContent = ((_a = cite.textContent) == null ? undefined : _a.replace("zhihu.com", "fxzhihu.com")) || "";
        }
      }
    });
  } else {
    window.location.replace(href.replace("zhihu.com", "fxzhihu.com"));
  }

})();