commit 20f5780b1abff1a021d15fe28e6ae9a528cda2ef Author: skscript Date: Sat Oct 28 12:11:47 2023 +0900 add kemono.user.js diff --git a/kemono.user.js b/kemono.user.js new file mode 100644 index 0000000..eb112f0 --- /dev/null +++ b/kemono.user.js @@ -0,0 +1,152 @@ +// ==UserScript== +// @name Go to kemono.party +// @name:ja kemono.partyへ移動 +// @namespace https://greasyfork.org/ja/users/1126644-s-k-script +// @version 0.1.2 +// @description Go to kemono.party from an artist's page. Supports Patreon, Pixiv, Fanbox and Fantia +// @description:ja アーティストのページから対応するkemono.partyのページへ移動します。Pixiv, Fanbox, Fantia, Patreonをサポートしています。 +// @author S.K.Script +// @homepage https://greasyfork.org/ja/users/1126644-s-k-script +// @license GPL-3.0-only +// @match https://fantia.jp/* +// @match https://*.fanbox.cc/* +// @match https://www.pixiv.net/* +// @match https://www.patreon.com/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=kemono.party +// @grant none +// @run-at context-menu +// ==/UserScript== + +(function() { + 'use strict'; + + class FantiaUrl { + static check(href) { + return !!href.match(/^https:\/\/fantia.jp/i); + } + + constructor(href) { + this.href = href; + } + + extract_user_id() { + const re = /https:\/\/fantia.jp\/fanclubs\/(?\d+)/i; + const match = this.href.match(re); + if(match) { + return {ok: match.groups.userid}; + } + else { + return {err: 'Try again in the top page of this fanclub.\nファンクラブのトップページに移動してからもう一度実行してください'}; + } + } + + generate_kemono_url(user_id) { + return 'https://kemono.party/fantia/user/' + user_id; + } + } + + class FanboxUrl { + static check(href) { + return !!href.match(/^https:\/\/\w+.fanbox.cc/i); + } + + constructor(href) { + this.href = href; + } + + extract_user_id() { + return {err: 'Try again in the Pixiv user page of this person. Note: Pixiv and Fanbox are run by the same company.\nこの人のPixiv(Fanboxではなく)のユーザーページへ移動してからもう一度実行してください'}; + } + + generate_kemono_url(user_id) { + return 'https://kemono.party/fanbox/user/' + user_id; + } + } + + class PixivUrl { + static check(href) { + return !!href.match(/https:\/\/www.pixiv.net/i); + } + + constructor(href) { + this.href = href; + } + + extract_user_id() { + const re = /https:\/\/www.pixiv.net\/users\/(?\d+)/i; + const match = href.match(re); + if(match) { + return {ok: match.groups.userid}; + } + else { + return {err: 'Try again in the Pixiv user page of this person.\nPixivのユーザーページに移動してからもう一度実行してください'}; + } + } + + generate_kemono_url(user_id) { + return 'https://kemono.party/fanbox/user/' + user_id; + } + } + + class PatreonUrl { + static check(href) { + return !!href.match(/https:\/\/www.patreon.com/i); + } + + constructor(href) { + this.href = href; + } + + extract_user_id() { + // https://www.patreon.com/user?u=35870453 + const re = /https:\/\/www.patreon.com\/user\?u=(?\d+)/i; + const match = href.match(re); + if(match) { + return {ok: match.groups.userid}; + } + else { + return {err: 'Try again in the Patreon user page of this person.\nPatreonのユーザーページに移動してからもう一度実行してください'}; + } + } + + generate_kemono_url(user_id) { + return 'https://kemono.party/patreon/user/' + user_id; + } + } + + const href = location.href; + + let url; + if(FantiaUrl.check(href)) { + url = new FantiaUrl(href); + } + else if(FanboxUrl.check(href)) { + url = new FanboxUrl(href); + } + else if(PixivUrl.check(href)) { + url = new PixivUrl(href); + } + else if(PatreonUrl.check(href)) { + url = new PatreonUrl(href); + } + else { + url = undefined; + } + + if(!url) { + window.alert('Not supported / 未対応/非対応です'); + return; + } + + const result = url.extract_user_id(); + if(result.ok) { + const user_id = result.ok; + const kemono_url = url.generate_kemono_url(user_id); + window.open(kemono_url, '_blank'); + } + else { + const err_message = result.err ? result.err : 'Error / なんかエラーだって'; + window.alert(err_message); + } + +})(); \ No newline at end of file