Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Kemono Party No Login Favorites
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @author You
- // @match https://kemono.party/*
- // @grant none
- // ==/UserScript==
- document.querySelector("ul.header").innerHTML = "<li><a href='/favorites'>Favorites</a></li>"+document.querySelector("ul.header").innerHTML;
- function map_to_array(mapobject){
- var output = [];
- mapobject.forEach((v,k) => {
- output.push([k,v]);
- });
- return output;
- }
- if(window.localStorage.userscript_favorites !== undefined && window.localStorage.userscript_favorites.length > 0){
- window.extension_favorites = new Map(JSON.parse(window.localStorage.userscript_favorites));
- }else{
- if(window.localStorage.favorites !== undefined && window.localStorage.favorites.length > 0){
- // convert existing old no-login favorites to extension format
- console.log("importing old favorites...");
- var old_favs = window.localStorage.favorites.split(",");
- for(let i = 0; i < old_favs.length; i++){
- let sp = old_favs[i].split(":");
- old_favs[i] = [
- "/"+sp[0]+"/user/"+sp[1],
- {
- display_name:"UNKNOWN (visit artist page to update)",
- id:sp[1],
- platform:sp[0]
- }
- ];
- }
- window.extension_favorites = new Map(old_favs);
- window.localStorage.userscript_favorites = JSON.stringify(map_to_array(window.extension_favorites));
- alert("existing favorites detected, importing to extension. extension will update artist names after you visit their page once.");
- console.log("favorites saved");
- }else{
- window.extension_favorites = new Map();
- }
- }
- window.add_extension_favorite = function(){
- document.getElementById("extension_favorite_button").innerText = "★ Favorited!";
- document.getElementById("extension_favorite_button").href = "javascript:window.remove_extension_favorite();";
- let sp = window.location.pathname.split("/user/");
- window.extension_favorites.set(window.location.pathname,{
- display_name:document.querySelector("#info-block a[href='"+window.location.pathname+"']").innerText,
- id:sp[1],
- platform:sp[0].replace("/","")
- });
- console.log("added favorite",window.location.pathname);
- window.save_extension_favorites();
- }
- window.remove_extension_favorite = function(){
- document.getElementById("extension_favorite_button").innerText = "☆ Favorite";
- document.getElementById("extension_favorite_button").href = "javascript:window.add_extension_favorite();";
- window.extension_favorites.delete(window.location.pathname);
- console.log("removed favorite",window.location.pathname);
- window.save_extension_favorites();
- }
- window.save_extension_favorites = function(){
- window.localStorage.userscript_favorites = JSON.stringify(map_to_array(window.extension_favorites));
- console.log("favorites saved");
- }
- if(window.location.href.indexOf("/user/") > -1 && document.querySelector("#info-block a[href^='javascript:favorite_artist']") !== null){
- // this replaces favorite button on artist pages with extension functionality
- document.querySelector("#info-block a[href^='javascript:favorite_artist']").id = "extension_favorite_button";
- document.getElementById("extension_favorite_button").href = "javascript:window.remove_extension_favorite();";
- if(window.extension_favorites.has(window.location.pathname)){
- document.getElementById("extension_favorite_button").innerText = "★ Favorited!";
- // this records artist names if it was an imported unknown artist
- if(window.extension_favorites.get(window.location.pathname).display_name == "UNKNOWN (visit artist page to update)"){
- let sp = window.location.pathname.split("/user/");
- window.extension_favorites.set(window.location.pathname,{
- display_name:document.querySelector("#info-block a[href='"+window.location.pathname+"']").innerText,
- id:sp[1],
- platform:sp[0].replace("/","")
- });
- console.log("unknown artist name updated");
- window.save_extension_favorites();
- }
- }
- }else if(window.location.href == "https://kemono.party/account/login"){
- document.querySelector("div.views").setAttribute("class","vertical-views");
- // when not logged in, clicking favorites redirects to login page.
- // this makes the login page show favorites, with login form still at bottom. if you're logged in, you'll see logged-in favorites, not extension favorites. artist favorite buttons won't work for account favorites though, disable the extension if you arent using it lol
- var build_html = `<table class="search-results" width="100%"><thead><tr><th width="50px">Icon</th><th>Name</th><th>Service</th></tr></thead><tbody>`;
- window.extension_favorites.forEach((fav,favurl) => {
- build_html += `<tr class="artist-row"><td><a href="`+favurl+`"><div class="user-icon" style="background-image: url('/icons/`+fav.platform+`/`+fav.id+`');"></div></a></td><td><a href="`+favurl+`">`+fav.display_name+`</a></td><td>`+fav.platform+`</td>`;
- });
- build_html += `</tbody></table><br>`;
- document.querySelector(".login-container").outerHTML = build_html + document.querySelector(".login-container").outerHTML;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement