Closed EnergoStalin closed 8 months ago
I'd rather not support this directly, I don't want artists to hate me. I've added a hook so you can add it for yourself. You can use it by creating a separate user script like this:
// ==UserScript==
// @name ppixiv hooks
// @include https://*.pixiv.net/*
// @grant none
// ==/UserScript==
window.vviewHooks = {
addUserLinks: ({ extraLinks, userInfo, userProfile }) => {
extraLinks.push({
url: "https://google.com",
label: "Google",
});
}
};
Note that userProfile will be null at first, once the profile finishes loading it'll be called again with it set.
Thanks i'm perfectly okay with that.
Tested it a little bit looks like it works not as expected when i add more code i have vviewHooks wiped away faster than it takes effect. Looks like you cleaning window object too well. You tiny example works fine tho.
Also the "Disabling createElement script app-startup.js:611:29" error constantly appearing when tampermonkey try to inject another script in fresh tab(not reload just new tab)
Firefox: 117.0 Tampermonkey: 4.19.0 ppixiv: 228
CPU: Intel i7-10700 (16) @ 4.800GHz GPU: NVIDIA GeForce GTX 1050 Ti
This amount of code enough for me to make it stop working.
// ==UserScript==
// @name ppixiv-kemono
// @namespace https://www.pixiv.net/
// @version 1.1.0
// @description Add Kemono Party buttons for ppixiv
// @author EnergoStalin
// @match https://*.pixiv.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @grant GM_xmlhttpRequest
// @connect www.patreon.com
// ==/UserScript==
window.vviewHooks = {
addUserLinks: ({ extraLinks, userInfo }) => {
console.log(extraLinks);
for(const link of extraLinks) {
switch(link.label) {
case "Fanbox":
extraLinks.push({
url: new URL(`https://kemono.party/fanbox/user/${userInfo.userId}`),
icon: "mat:money_off",
label: "Kemono fanbox"
});
break;
case "patreon.com":
break;
}
}
}
};
Looks like very unstable solution in current state.
If you don't use @grant none then your script will be sandboxed and you'll have a different window object. You may be able to use unsafeWindow instead, but that might not work in Firefox with its broken sandboxing. Using grant none should work everywhere, but if you want to @connect you'd need to jump some hoops, like running a separate sandboxed script and talking to it with messaging, like I do with gm-download.
Works perfectly fine with unsafeWindow. I thinked about sandboxing and knew about unsafeWindow but figuring it out not today.
EDIT: i think @ unwrap better option now
Also it would be nice have some hook to request redraw or maybe make hook context async. Because when you need to load some data and add it later it becomes not so straightforward as with static. Like patreon id for example
Looks like i can fix it by caching id's but sometimes it works only on second open
const cachedPatreonUsers = {};
const url = link.url.toString();
const cachedId = cachedPatreonUsers[url];
if(!cachedId) {
getPatreonId(url).then(id => {cachedPatreonUsers[url] = id}).catch(console.log)
} else {
extraLinks.push({
url: new URL(`https://kemono.party/patreon/user/${cachedId}`),
icon: "mat:money_off",
type: "kemono_patreon",
label: "Kemono patreon"
});
}
That might not work if API calls finish in a different order. You should be able to trigger a refresh with:
unsafeWindow.ppixiv.userCache.callUserModifiedCallbacks(userInfo.userId);
Of course only call it when you have new data, so you don't refresh endlessly.
Added https://kemono.party shortcut for users with fanbox link.
Didn't test it tho cause i'm too stupid for understanding build system of this project. So feedback appreciated.
I implemented hotfix for myself but it's a little bit tricky so i want to have it in official way if possible. Unfortunately can't make it work on mobile until now(Yandex Browser, Firefox)