view mandarake-direct-link.user.js @ 49:2e1cae72a63e

Semicolons
author nanaya <me@nanaya.pro>
date Thu, 12 Oct 2017 16:40:13 +0900
parents b60f0fd9c417
children f0d5a5d80bfd
line wrap: on
line source

// ==UserScript==
// @name         mandarake direct link
// @namespace    https://myconan.net
// @version      1.3.0
// @description  Make proper link on mandarake pages
// @author       nanaya
// @match        https://order.mandarake.co.jp/*
// @match        http://order.mandarake.co.jp/*
// @grant        none
// @downloadURL  https://bitbucket.org/!api/2.0/snippets/nanayapro/TK64/tip/files/mandarake-direct-link.user.js
// ==/UserScript==

;(function() {
  "use strict";
  $(".r18mark").remove();
  var fixR18Link = function(_i, el) {
    var url = `/order/detailPage/item?itemCode=${el.id}`;

    el.setAttribute("href", url);
    el.setAttribute("class", "");
  };

  $("[href^='#adult_confirm']").each(fixR18Link);

  var currentQuery = new URLSearchParams(location.search);
  var fixSearchLink = function(_i, el) {
    var query = new URLSearchParams(el.search);

    for (let [key, value] of currentQuery) {
      if (!query.has(key)) {
        query.set(key, value);
      }
    }

    el.setAttribute("href", `/order/listPage/list?${query.toString()}`);
  };

  $("[href^='/order/listPage/list?']").each(fixSearchLink);
}).call();