kemono.su links for ppixiv

Add kemono.su patreon & fanbox & fantia links into ppixiv

目前为 2024-11-21 提交的版本。查看 最新版本

// ==UserScript==
// @name          kemono.su links for ppixiv
// @author        EnergoStalin
// @description   Add kemono.su patreon & fanbox & fantia links into ppixiv
// @license       AGPL-3.0-only
// @version       1.7.1
// @namespace     https://pixiv.net
// @match         https://*.pixiv.net/*
// @run-at        document-body
// @icon          https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @connect       gumroad.com
// @connect       www.patreon.com
// @connect       kemono.su
// @connect       nekohouse.su
// @grant         GM.xmlHttpRequest
// ==/UserScript==

"use strict";(()=>{var M=Object.defineProperty;var n=(t,e)=>M(t,"name",{value:e,configurable:!0});var s=(t,e,o)=>new Promise((r,a)=>{var l=c=>{try{p(o.next(c))}catch(g){a(g)}},u=c=>{try{p(o.throw(c))}catch(g){a(g)}},p=c=>c.done?r(c.value):Promise.resolve(c.value).then(l,u);p((o=o.apply(t,e)).next())});function P(t){let e=new URL(t);return e.pathname=`/api/v1${e.pathname}/profile`,e.toString()}n(P,"toApiUrl");function x(t){return s(this,null,function*(){let e=P(t),o=yield GM.xmlHttpRequest({url:e});if(o.status===404)throw"Creator dont exists";return{lastUpdate:JSON.parse(o.responseText).updated.split("T")[0]}})}n(x,"getCreatorData");function w(t){return x(t)}n(w,"getPostData");var S=/datetime="(.+)?"/,z=/datetime="(.+)?"/;function b(t){return s(this,null,function*(){let e=yield GM.xmlHttpRequest({method:"GET",url:t});if(e.finalUrl!==t)throw new Error(`creator does not exists ${t}`);return e.responseText})}n(b,"fetchPage");function y(t){return s(this,null,function*(){var o,r;return{lastUpdate:(r=(o=(yield b(t)).match(S))==null?void 0:o[1])==null?void 0:r.split(" ")[0]}})}n(y,"getCreatorData");function D(t){return s(this,null,function*(){var o,r;return{lastUpdate:(r=(o=(yield b(t)).match(z))==null?void 0:o[1])==null?void 0:r.split(" ")[0]}})}n(D,"getPostData");function E(t){return s(this,null,function*(){if(t.includes("kemono"))return t.includes("post")?w(t):x(t);if(t.includes("nekohouse"))return t.includes("post")?D(t):y(t);throw new Error(`unknown url ${t}`)})}n(E,"getCreatorData");function I(t){return t.charAt(0).toUpperCase()+t.slice(1)}n(I,"capitalize");function i(t,e,o,r){let a=r?`/post/${r}`:"";return{url:new URL(`https://${t}.su/${e}/user/${o}/${a}`),icon:"mat:money_off",type:`${t}_${e}#{userId}`,label:`${I(t)} ${e}`}}n(i,"makeUrl");function m(t){let e=t.trim();return e.startsWith("http")||(e=`https://${e}`),e}n(m,"normalizeUrl");var L=/[\W\s]((?:https?:\/\/)?(?:\w+[\.\/])+(?:\w?)+)/g,k={patreon:"patreon.com",fanbox:"Fanbox",fantia:"fantia.jp",gumroad:"gumroad.com"};function O(t){return t.map(e=>{try{let o=new URL(m(e));return{label:k[Object.keys(k).find(r=>o.host.includes(r))],url:o}}catch(o){}})}n(O,"preprocessMatches");function R(t){let o=document.body.querySelector(".description").innerText.replaceAll(/\/\s+/g,"/").replaceAll("(dot)",".");return v(O(Array.from(o.matchAll(L)).map(r=>r[1])).filter(r=>r),t)}n(R,"getLinksFromDescription");function v(t,e){let o=e.map(r=>r.label);return t.filter(r=>!o.includes(r.label))}n(v,"removeDuplicates");function f(t){unsafeWindow.ppixiv.userCache.callUserModifiedCallbacks(t)}n(f,"notifyUserUpdated");function W(t){let e=0;if(t.length===0)return e;for(let o=0;o<t.length;o++)e+=t.charCodeAt(o);return e}n(W,"fastHash");var d={};function q(t){return s(this,null,function*(){try{let e=yield E(t);d[t]={redirected:!1,lastUpdate:e.lastUpdate}}catch(e){console.error(e),d[t]={redirected:!0}}})}n(q,"cacheRequest");var U=new Set;function _(t,e){let o=W(JSON.stringify(t));U.has(o)||(U.add(o),Promise.all(t.filter(r=>d[r.url.toString()]===void 0).map(r=>q(r.url.toString()))).then(r=>{U.delete(o),r.length>0&&f(e)}).catch(console.error));for(let r of t){let a=d[r.url.toString()];(a==null?void 0:a.redirected)===!0?(r.label+=" (Redirected)",r.disabled=!0):a===void 0?r.disabled=!0:r.label+=` (${a.lastUpdate})`}return t}n(_,"checkAvalibility");function C(t,e){t.push(i("kemono","fanbox",e)),t.push(i("nekohouse","fanbox",e))}n(C,"fanbox");function T(t,e){let o=t.url.toString().split("/").pop();e.push(i("kemono","fantia",o)),e.push(i("nekohouse","fantia",o))}n(T,"fantia");function h(t){let e=new Map,o=!1;return function(r,a,...l){if(o)return;o=!0;let u=l[0];if(e.has(u))return o=!1,r(e.get(u));t.apply(this,l).then(p=>{e.set(u,p),f(a),o=!1})}}n(h,"memoize");var F=/"external_id":"(\d+)"/,H=h(t=>s(void 0,null,function*(){return GM.xmlHttpRequest({method:"GET",timeout:5e3,url:t}).then(e=>{var o,r;return(r=(o=e.responseText.match(F))==null?void 0:o[1])!=null?r:"undefined"}).catch(console.error)}));function A(t,e,o){H(r=>{if(!r){t.disabled=!0;return}e.push(i("kemono","gumroad",r)),e.push(i("nekohouse","gumroad",r))},o,t.url.toString())}n(A,"gumroad");function N(t){typeof t.url=="string"&&(t.url=new URL(m(t.url))),t.url.protocol="https",t.url.host.startsWith("www.")||(t.url.host=`www.${t.url.host}`)}n(N,"normalizePatreonLink");var X=new RegExp('"id":\\s*"(\\d+)",[\\n\\s]*"type":\\s*"user"',"ms"),j=h(t=>s(void 0,null,function*(){return GM.xmlHttpRequest({method:"GET",timeout:5e3,url:t}).then(e=>{var o,r;return(r=(o=e.responseText.match(X))==null?void 0:o[1])!=null?r:"undefined"}).catch(console.error)}));function $(t,e,o){N(t);let r=t.url.toString();j(a=>{if(!a){t.disabled=!0;return}e.push(i("kemono","patreon",a)),e.push(i("nekohouse","patreon",a))},o,r)}n($,"patreon");function G(t,e){let o=[];for(let r of[...t,...R(t)])switch(r.label){case"Fanbox":C(o,e);break;case"patreon.com":$(r,o,e);break;case"gumroad.com":A(r,o,e);break;case"fantia.jp":T(r,o);break;default:}return o}n(G,"genLinks");var K=n(({extraLinks:t,userInfo:e})=>{let o=G(t,e.userId),r=_(o,e.userId);t.push(...r)},"addUserLinks");unsafeWindow.vviewHooks={addUserLinks:K};})();