etools QOL improvements

...

当前为 2024-06-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        etools QOL improvements
// @namespace   Violentmonkey Scripts
// @match       https://www.etools.ch/searchSubmit.do*
// @grant       none
// @version     1.0
// @author      Headsman2236
// @license     AGPL-3.0-or-later
// @description ...
// @require     https://openuserjs.org/src/libs/sizzle/GM_config.min.js
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM.getValue
// @grant       GM.setValue
// ==/UserScript==

// TODO: Achieve better safety
//
// TODO: Support mobile and support engine-specific search with these options
// Not here but in the CSS Stylish add an option to disable the highlight

// TODO: Add a proper userscript config with GM_config
// -  @see https://github.com/sizzlemctwizzle/GM_config/wiki/
// TODO: Use proper JSDoc annotations on the config object for all the properties
const config = {
  disableMobileLink: true,
  /** Bring the "By Topic:" menu to the top of the right sidebar **/
  bringByTopicToTop: true,
  moveSearchStatusesToBottom: true,
  displayFullLink: true,
  faviSources: false,
  showFavi: true, // Fetches the favicon from the sites in a bare proxy
  preview: {
    disable: true,
    // This would allow for any site to be iframed with the preview feature, bringing preview to any site, using aero
    proxyPreview: true
  }
}

if (config.moveSearchStatusesToBottom) {
  const results = document.getElementsByClassName("result")[0];
  const resultsTable = results.parentNode;
  const statuses = [...document.getElementsByClassName("searchStatus")].filter(status => resultsTable.contains(status));
  statuses.at(-1).style["padding-bottom"] = "15px";
  statuses.forEach(status => {
    resultsTable.appendChild(status);
  });
}

if (config.disableMobileLink) {
  [...document.getElementsByTagName("a")].find(link => link.href = "mobileSearch.do").removeAttribute("href");
  // Consider: Perhaps I should add "mobile version" to the sidebar instead and make the favicon just redirect to the real home page, not the mobile version of the site? It would be a more logical place to put the mobile version.
}

if (config.bringByTopicToTop) {
  // const sidebarLeft = [...document.getElementsByTagName("td")][100];
  const sourceBox = [...document.getElementsByClassName("boxTop")][2];
  const resultsToolTitle = [...document.getElementsByTagName("h3")].find(title => title.textContent === "Results Tool");
  if (resultsToolTitle)
    resultsToolTitle.insertAdjacentElement("afterend", sourceBox);
}

if (config.displayFullLink) {
  const searchEntries = [...document.getElementsByClassName("record")];
  for (const searchEntry of searchEntries) {
    const children = [...searchEntry.children];
    const titleLink = children[0].href;
    if (titleLink) {
      const attrChildren = [...children[2].children];
      const displayLink = attrChildren[0];
      displayLink.innerText = titleLink;
    }
  }
}

if (config.faviSources) {
  const links = [...document.getElementsByTagName("a")];
  const engineToFavi = new Map();
  // TODO: Find HD sources for each favicon
  // TODO: Finish adding all of the sources
  engineToFavi.set("Brave", "https://cdn.search.brave.com/serp/v2/_app/immutable/assets/favicon-32x32.B2iBzfXZ.png");
  engineToFavi.set("DuckDuckGo", "https://duckduckgo.com/favicon.ico");
  engineToFavi.set("Google", "https://www.google.com/favicon.ico");
  engineToFavi.set("Mojeek", "https://www.mojeek.com/favicon.ico");
  engineToFavi.set("Qwant", "https://www.qwant.com/favicon.ico");
  engineToFavi.set("Wikipedia", "https://www.wikipedia.org/static/favicon/wikipedia.ico");
  engineToFavi.set("Yandex", "https://yastatic.net/s3/home-static/_/nova/7f2537ce.png");

  for (let [text, faviLink] of engineToFavi) {
    const ddgs = links.filter(link => link.innerText === text);
    ddgs.forEach(ddg => {
      ddg.innerText = "";
      const favi = document.createElement("img");
      favi.src = faviLink;
      favi.style.width = "20px";
      favi.style.height = "20px";
      // TODO: Keep the link to the search engine but append the current query to it
      ddg.insertAdjacentElement("afterend", favi);
    })
  }
}


const pipeText = " | ";

// FIXME: Doesn't work on Engine-specific search
[...document.getElementsByTagName("a")].filter(link => link.textContent === "preview" && /^p\d/.test(link.id)).forEach(previewLink => {
  const pipe = previewLink.previousSibling;
  // Parity check
  if (pipe.textContent === pipeText) {
    pipe.remove();
  }
  previewLink.remove();
});

// TODO: Add the "proxy preview" feature
if (config.proxyPreview) {
  /*
  [...document.getElementsByClassName("attr")].forEach(attr => {
      [...attr.childNodes].forEach(child => {
          if (child.nodeType === Node.TEXT_NODE) {
              const isPipe = child.textContent === pipeText;
              const isSource = child.textContent === "Source: ";
              if (config.faviSources && (isPipe || isSource))
                ...
          }
      });
  })
  */
}