DLsite Affiliate Formatter

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

Από την 20/06/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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();
})();