Phixiv Share

Add Phixiv Share button to pixiv

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Phixiv Share
// @namespace    https://github.com/gjing/phixiv-share
// @version      1.1.1
// @description  Add Phixiv Share button to pixiv
// @author       gjing
// @match        https://www.pixiv.net/*
// @run-at       document-idle
// @license      MIT
// ==/UserScript==
(function() {
  'use strict';

  let url = location.href;
  document.body.addEventListener('click', ()=>{
    requestAnimationFrame(()=>{
      if (url!==location.href) {
        url = location.href;
        const element = document.getElementsByClassName("sc-181ts2x-0")[0].remove();
      	wait_icon();
      }
    });
  }, true);
	
  function wait_icon() {
    const intv = setInterval(function() {
      const nav_bar = document.getElementsByClassName("sc-181ts2x-0");
      if (nav_bar.length == 0) {
        return false;
      }
      clearInterval(intv);
      load_icon();
    }, 100);
  }

  function load_icon() {
    const link = window.location.href.replace("pixiv", "phixiv");
    const element = document.getElementsByClassName("sc-181ts2x-0")[0];
    const div_string = '<div class="sc-181ts2x-7"><button type="button" class="y35SzDmKENoCKvur"><span class="Gi9zOhEDaI9fmUNA">PHIX</span></button></div>';
    const div = document.createElement('div');
    div.innerHTML = div_string;
    div.style.paddingRight = '10px';
    div.onclick = function() {
      navigator.clipboard.writeText(link);
    }
    element.appendChild(div);
  }
  
  wait_icon();
})();