DLsite Affiliate Formatter

DLsiteのアフィリエイトリンクをどこでも作れる便利なやつ

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DLsite Affiliate Formatter
// @namespace    http://mizle.net/
// @version      0.1.2
// @description  DLsiteのアフィリエイトリンクをどこでも作れる便利なやつ
// @author       eai04191
// @license      MIT
// @supportURL   https://github.com/eai04191/DLsiteAffiliateFormatter/issues
// @match        http://www.dlsite.com/home/*
// @match        http://www.dlsite.com/soft/*
// @match        http://www.dlsite.com/comic/*
// @match        http://www.dlsite.com/maniax/*
// @match        http://www.dlsite.com/pro/*
// @match        http://www.dlsite.com/books/*
// @match        http://www.dlsite.com/girls/*
// @match        http://www.dlsite.com/girls-pro/*
// @match        http://www.dlsite.com/gay/*
// @match        http://www.dlsite.com/eng/*
// @match        http://www.dlsite.com/ecchi-eng/*
// @grant        none
// ==/UserScript==

(function () {
  "use strict";

  const affiliateID = "eai04191";

  function headerInjection() {
    let header = document.getElementsByClassName("eisysGroupHeaderAccount")[0];
    let title = document.title;
    let URL = location.href;

    let category = URL.match(/dlsite.com\/(home|soft|comic|maniax|pro|books|girls|girls-pro|gay|eng|ecchi-eng)\//)[1];

    let affiliateURL = "";
    if (/work\/=\/product_id\//.test(URL)) {
      // 作品ページ
      let workID = URL.match(/(..\d{6})/)[1];
      affiliateURL = `http://www.dlsite.com/${category}/dlaf/=/link/work/aid/${affiliateID}/id/${workID}.html`;
    } else {
      // 作品以外のページ
      affiliateURL = `http://www.dlsite.com/${category}/dlaf/=/aid/${affiliateID}/url/${encodeURIComponent(URL)}`;
    }

    let tweetURLBase = "https://twitter.com/intent/tweet?text=";
    let tweetText = `${title} ${affiliateURL}`;

    let injectionHTML = `
<li class="eisysGroupHeaderService-link type-dlsite" id="dlaf">
<a href="${tweetURLBase + encodeURIComponent(tweetText)}" target="_blank" id="dlaf-tweet">ツイート</a>
<a href="#" id="dlaf-copy-url">URLコピー</a>
<a href="#" id="dlaf-copy-md">MDコピー</a>
</li>`;
    header.innerHTML = injectionHTML + header.innerHTML;

    document.getElementById("dlaf-copy-url").onclick = function () {
      window.prompt("Copy to clipboard: Ctrl+C, Enter", affiliateURL);
    };

    document.getElementById("dlaf-copy-md").onclick = function () {
      let md = `[${title}](${affiliateURL})`;
      window.prompt("Copy to clipboard: Ctrl+C, Enter", md);
    };
  }

  headerInjection();
})();