DLsite Affiliate Formatter

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

Tính đến 20-06-2018. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         DLsite Affiliate Formatter
// @namespace    http://mizle.net/
// @version      0.1
// @description  DLsiteのアフィリエイトリンクをどこでも作れる便利なやつ
// @author       eai04191
// @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+).html/)[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();
})();