skeb-request-auto-link

The auto link for requests of Skeb.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     skeb-request-auto-link
// @version  1.6
// @grant    none
// @include  https://skeb.jp/*
// @description The auto link for requests of Skeb.
// @license MIT
// @namespace https://greasyfork.org/users/114367
// ==/UserScript==

const makeLink = elm => {
  if (elm.nodeType != 3) return elm;
  if (elm.textContent.match(/([\s\S]*)(https?:\/\/[\w!?\/+\-=_~;.,*&@#$%()'[\]]+)([\s\S]*)/m)) {
    const pre = RegExp.$1;
    const url = RegExp.$2;
    const next = RegExp.$3;
    const f = document.createDocumentFragment();
    f.appendChild(makeLink(document.createTextNode(pre)));
    const link = document.createElement('A');
    link.textContent = url;
    link.href = url;
    link.target = '_blank';
    link.rel = 'noreferrer';
    link.className = 'skeb-request-auto-link';
    f.appendChild(link);
    f.appendChild(makeLink(document.createTextNode(next)));
    return f;
  } else {
    return elm;
  }
};

const execute = () => {
  for (const panel of document.getElementsByClassName('panel-block')) {
    if (panel.getAttribute('data-skebrequestautolink')) continue;
    panel.setAttribute('data-skebrequestautolink', true);
    for (const lines of panel.getElementsByClassName('pre-line')) {
      lines.replaceChild(makeLink(lines.firstChild), lines.firstChild);
    }
  }
};

let timer = setTimeout(execute, 1000);
const observer = new MutationObserver(rec => {
  clearTimeout(timer);
  timer = setTimeout(execute, 1000);
});
observer.observe(document.body, { childList: true, subtree: true });

const style = document.createElement('STYLE');
style.textContent = `
  .skeb-request-auto-link { transition: .2s; }
  .skeb-request-auto-link:hover { background: #0962; }
`;
document.head.appendChild(style);