2023-10-28 12:11:47 +09:00
// ==UserScript==
2023-10-28 12:33:53 +09:00
// @name Go to kemono.su
// @name:ja kemono.suへ移動
2023-10-28 12:11:47 +09:00
// @namespace https://greasyfork.org/ja/users/1126644-s-k-script
// @version 0.1.2
2023-10-28 12:33:53 +09:00
// @description Go to kemono.su from an artist's page. Supports Patreon, Pixiv, Fanbox and Fantia
// @description:ja アーティストのページから対応するkemono.suのページへ移動します。Pixiv, Fanbox, Fantia, Patreonをサポートしています。
2023-10-28 12:11:47 +09:00
// @author S.K.Script
2023-10-28 12:33:53 +09:00
// @homepage https://gitler.moe/skscript/redirect2kemono
2023-10-28 12:11:47 +09:00
// @license GPL-3.0-only
// @match https://fantia.jp/*
// @match https://*.fanbox.cc/*
// @match https://www.pixiv.net/*
// @match https://www.patreon.com/*
2023-10-28 12:33:53 +09:00
// @match https://kemono.su/*
// @match https://kemono.party/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=kemono.su
2023-10-28 12:11:47 +09:00
// @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 ;
}
2023-10-28 12:46:14 +09:00
extract _metadata ( ) {
2023-10-28 12:11:47 +09:00
const re = /https:\/\/fantia.jp\/fanclubs\/(?<userid>\d+)/i ;
const match = this . href . match ( re ) ;
if ( match ) {
return { ok : match . groups . userid } ;
}
else {
2023-10-28 12:49:16 +09:00
document . querySelectorAll ( ".fanclub-name > a" ) . forEach ( element => {
2023-10-28 12:50:27 +09:00
console . log ( element ) ;
2023-10-28 12:49:16 +09:00
const match = element . href . match ( re ) ;
if ( match ) {
return { ok : match . groups . userid } ;
}
} )
2023-10-28 12:11:47 +09:00
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 ;
}
2023-10-28 12:46:14 +09:00
extract _metadata ( ) {
2023-10-28 12:11:47 +09:00
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 ;
}
2023-10-28 12:46:14 +09:00
extract _metadata ( ) {
2023-10-28 12:11:47 +09:00
const re = /https:\/\/www.pixiv.net\/users\/(?<userid>\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 ;
}
2023-10-28 12:46:14 +09:00
extract _metadata ( ) {
2023-10-28 12:11:47 +09:00
// https://www.patreon.com/user?u=35870453
const re = /https:\/\/www.patreon.com\/user\?u=(?<userid>\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 ;
}
}
2023-10-28 12:39:35 +09:00
class KemonoUrl {
static check ( href ) {
2023-10-28 12:44:58 +09:00
return ! ! href . match ( /https:\/\/kemono.(su|party)/i ) ;
2023-10-28 12:39:35 +09:00
}
constructor ( href ) {
this . href = href ;
}
2023-10-28 12:46:14 +09:00
extract _metadata ( ) {
2023-10-28 12:44:58 +09:00
const re = /https:\/\/kemono.(su|party)\/(?<platform>\w+)\/user\/(?<userid>\d+)/i ;
2023-10-28 12:39:35 +09:00
const match = href . match ( re ) ;
if ( match ) {
return { ok : { userid : match . groups . userid , platform : match . groups . platform } } ;
}
else {
return { err : '?' } ;
}
}
2023-10-28 12:46:14 +09:00
generate _kemono _url ( metadata ) {
return 'https://kemono.su/' + metadata . platform + '/user/' + metadata . userid ;
2023-10-28 12:39:35 +09:00
}
}
2023-10-28 12:11:47 +09:00
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 ) ;
}
2023-10-28 12:39:35 +09:00
else if ( KemonoUrl . check ( href ) ) {
url = new KemonoUrl ( href ) ;
}
2023-10-28 12:11:47 +09:00
else {
url = undefined ;
}
if ( ! url ) {
window . alert ( 'Not supported / 未対応/非対応です' ) ;
return ;
}
2023-10-28 12:46:14 +09:00
const result = url . extract _metadata ( ) ;
2023-10-28 12:11:47 +09:00
if ( result . ok ) {
2023-10-28 12:46:14 +09:00
const metadata = result . ok ;
const kemono _url = url . generate _kemono _url ( metadata ) ;
2023-10-28 12:11:47 +09:00
window . open ( kemono _url , '_blank' ) ;
}
else {
const err _message = result . err ? result . err : 'Error / なんかエラーだって' ;
window . alert ( err _message ) ;
}
} ) ( ) ;