view mandarake-direct-link.user.js @ 136:1e64e81370a3 default tip

Add nginx-https
author nanaya <me@nanaya.net>
date Tue, 27 Feb 2024 01:17:43 +0900
parents 59c8866710f8
children
line wrap: on
line source

// ==UserScript==
// @name        mandarake direct link
// @namespace   https://nanaya.net
// @version     2.0.3
// @description Make proper link on mandarake pages
// @author      nanaya
// @match       https://order.mandarake.co.jp/*
// @match       http://order.mandarake.co.jp/*
// @grant       none
// @run-at      document-start
// @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js
// ==/UserScript==

'use strict';

const r18ConfirmLink = '#adult_confirm';
function fixR18Link (link) {
  if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return;

  link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`);
  link.removeAttribute('class');
}

function removeR18Mark (node) {
  if (node.classList.contains('r18mark')) {
    node.remove();
    return true;
  }

  for (const mark of node.querySelectorAll('.r18mark')) {
    mark.remove();
  }
}

function run (node) {
  if (!(node instanceof window.HTMLElement)) return;
  if (removeR18Mark(node)) return;

  fixR18Link(node);
  for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
    fixR18Link(link);
  }
}

function onMutate (mutations) {
  for (const mutation of mutations) {
    for (const node of mutation.addedNodes) {
      run(node);
    }

    run(mutation.target);
  }
}

const observer = new window.MutationObserver(onMutate);
observer.observe(document, { childList: true, subtree: true });
run(document.body);