Skip to content

Instantly share code, notes, and snippets.

@Shiroizu
Last active January 14, 2025 19:08
Show Gist options
  • Save Shiroizu/faf59e536fcdd019f66e7d2cf682c082 to your computer and use it in GitHub Desktop.
Save Shiroizu/faf59e536fcdd019f66e7d2cf682c082 to your computer and use it in GitHub Desktop.
javascript:( function() { var ch = (window.location.host == "ch.nicovideo.jp"); if (window.location.host == "www.nicolog.jp" && window.location.pathname.startsWith("/user/")) { var videos = document.querySelectorAll("table a"); var limit = videos.length - 1; var i = -1; var delay = 500; function addButton(linkText, color, buttonLink, floatDirection, btnLocation) { var btn = document.createElement("a"); var textNode = document.createTextNode(linkText); btn.appendChild(textNode); btn.style.backgroundColor = color; btn.style.color = "black"; btn.style.padding = "7px 14px"; btn.style.border = "1px solid black"; btn.style.float = floatDirection; if (floatDirection == "right") { btn.style.float = "left"; btn.style.marginLeft = "10px"; } else { btn.style.marginTop = "17px"; } btn.href = buttonLink; btn.target = "_blank"; document.querySelector(btnLocation).appendChild(btn); } function checkVideos() { setTimeout(function() { i++; var videoId = videos[i].href.split("?")[0].split("/")[4]; var btnLocation = 'a[href="watch/' + videoId + '"]'; let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId; let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (xhttp.responseText == "null") { var green = "#b0e8fc"; addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ "https://www.nicolog.jp/watch/" + videoId, "left", btnLocation); addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + "https://www.nicovideo.jp/watch/" + videoId, "right", btnLocation); } else { var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id; var blue = "#8ef990"; addButton("Song Entry", blue, entryLink, "left", btnLocation); } } }; xhttp.open("GET", apiUrl, false); xhttp.send(); if (i < limit) { checkVideos(); } }, delay); } checkVideos(); } else if (ch || ((window.location.host == "www.nicovideo.jp") && (!window.location.pathname.startsWith("/watch/")))) { if (ch || ((window.location.pathname.startsWith("/tag/") || (window.location.pathname.startsWith("/search/"))))) { var delay = 200; var minViews = 50; var minScore = 5; var skipTitlesWith = ["on vocal", "off vocal"]; if (ch) { var videos = document.querySelectorAll(".item"); } else { var videos = document.querySelectorAll("div.videoList ul:nth-child(2) li.item"); } var i = -1; function addButton(linkText, color, buttonLink, floatDirection, btnLocation) { var btn = document.createElement("a"); var textNode = document.createTextNode(linkText); btn.appendChild(textNode); btn.style.backgroundColor = color; btn.style.color = "black"; btn.style.padding = "7px 14px"; btn.style.border = "1px solid black"; btn.style.cssFloat = floatDirection; btn.href = buttonLink; btn.target = "_blank"; if (ch) { document.querySelector(btnLocation).parentElement.parentElement.appendChild(btn); } else { document.querySelector(btnLocation).appendChild(btn); } } function checkVideos() { setTimeout(function() { var limit; var skip = false; i++; let title, data, views, likes, mylists, videoId, btnLocation; if (ch) { limit = 19; title = videos[i].querySelector(".title").innerText; data = videos[i].querySelector(".counts"); views = data.querySelector(".view var").innerText.replaceAll(",", ""); mylists = data.querySelector(".mylist var").innerText.replaceAll(",", ""); videoId = videos[i].querySelector("a").href; btnLocation = 'a[href="' + videoId + '"]'; videoId = videoId.split("/watch/")[1]; if (views < minViews || !(mylists > minScore)) {skip = true;} } else { limit = 31; title = videos[i].querySelector(".itemTitle").innerText; data = videos[i].querySelector(".itemData"); views = data.querySelector(".view .value").innerText.replaceAll(",", ""); likes = data.querySelector(".like .value").innerText.replaceAll(",", ""); mylists = data.querySelector(".mylist .value").innerText.replaceAll(",", ""); videoId = videos[i].attributes["data-video-id"].nodeValue; btnLocation = 'li[data-video-id=' + videoId + ']'; if (views < minViews || !(mylists > minScore || likes > minScore)) {skip = true;} } if (skipTitlesWith.some(word => title.includes(word))) {skip = true;} if (!skip) { let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId; let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (xhttp.responseText == "null") { var nicoUrl = "https://www.nicovideo.jp/watch/" + videoId; var green = "#b0e8fc"; addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ nicoUrl, "left", btnLocation); addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + nicoUrl, "right", btnLocation); } else { var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id; var blue = "#8ef990"; addButton("Song Entry", blue, entryLink, "left", btnLocation); } } }; xhttp.open("GET", apiUrl, false); xhttp.send(); } if (i < limit) { checkVideos(); } }, delay); } checkVideos(); } else if (window.location.pathname.startsWith("/user/")) { var videos = document.querySelectorAll(".VideoMediaObjectList a.NC-MediaObject-contents"); var limit = videos.length - 1; var i = -1; var delay = 500; function addButton(linkText, color, buttonLink, floatDirection, btnLocation) { var btn = document.createElement("a"); var textNode = document.createTextNode(linkText); btn.appendChild(textNode); btn.style.backgroundColor = color; btn.style.color = "black"; btn.style.padding = "7px 14px"; btn.style.border = "1px solid black"; btn.style.position = "absolute"; btn.style.marginTop = "80px"; if (floatDirection == "right") { btn.style.marginLeft = "100px"; } btn.href = buttonLink; btn.target = "_blank"; document.querySelector(btnLocation).appendChild(btn); } function checkVideos() { setTimeout(function() { i++; var videoId = videos[i].href.split("?")[0].split("/")[4]; var btnLocation = 'a[href="https://www.nicovideo.jp/watch/' + videoId + '"]'; let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId; let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (xhttp.responseText == "null") { var nicoUrl = "https://www.nicovideo.jp/watch/" + videoId; var green = "#b0e8fc"; addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ nicoUrl, "left", btnLocation); addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + nicoUrl, "right", btnLocation); } else { var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id; var blue = "#8ef990"; addButton("Song Entry", blue, entryLink, "left", btnLocation); } } }; xhttp.open("GET", apiUrl, false); xhttp.send(); if (i < limit) { checkVideos(); } }, delay); } checkVideos(); } } else if (["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"].indexOf(window.location.host) !== -1) { var videoUrl = ""; if (window.location.host === "www.youtube.com") { videoUrl = window.location.href.split("&")[0]; } else { videoUrl = window.location.href.split("?")[0]; } var pvsApiUrl = "https://vocadb.net/api/pvs?getTitle=false&pvUrl="; var pvInfo = new XMLHttpRequest(); pvInfo.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var service = JSON.parse(pvInfo.responseText).service; var videoID = JSON.parse(pvInfo.responseText).pvId; checkDB(service, videoID); } else if (this.status === 400) { alert("Video ID not found for " + videoUrl); this.onreadystatechange = null; } }; pvInfo.open("GET", pvsApiUrl + videoUrl, true); pvInfo.send(); function checkDB(service, videoID) { var apiUrl = "https://vocadb.net/api/songs/byPV?pvService=" + service + "&pvId=" + videoID; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (xhttp.responseText != "null") { window.location.assign("https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id); } else { window.open("https://vocadb.net/Song/Create?pvUrl=" + videoUrl); } } }; xhttp.open("GET", apiUrl, true); xhttp.send(); } } else { alert("Invalid URL"); return; } })();
javascript:(
function() {
var ch = (window.location.host == "ch.nicovideo.jp");
if (window.location.host == "www.nicolog.jp" && window.location.pathname.startsWith("/user/")) {
var videos = document.querySelectorAll("table a");
var limit = videos.length - 1;
var i = -1;
var delay = 500;
function addButton(linkText, color, buttonLink, floatDirection, btnLocation) {
var btn = document.createElement("a");
var textNode = document.createTextNode(linkText);
btn.appendChild(textNode);
btn.style.backgroundColor = color;
btn.style.color = "black";
btn.style.padding = "7px 14px";
btn.style.border = "1px solid black";
btn.style.float = floatDirection;
if (floatDirection == "right") {
btn.style.float = "left";
btn.style.marginLeft = "10px";
} else {
btn.style.marginTop = "17px";
}
btn.href = buttonLink;
btn.target = "_blank";
document.querySelector(btnLocation).appendChild(btn);
}
function checkVideos() {
setTimeout(function() {
i++;
var videoId = videos[i].href.split("?")[0].split("/")[4];
var btnLocation = 'a[href="watch/' + videoId + '"]';
let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (xhttp.responseText == "null") {
var green = "#b0e8fc";
addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ "https://www.nicolog.jp/watch/" + videoId, "left", btnLocation);
addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + "https://www.nicovideo.jp/watch/" + videoId, "right", btnLocation);
} else {
var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id;
var blue = "#8ef990";
addButton("Song Entry", blue, entryLink, "left", btnLocation);
}
}
};
xhttp.open("GET", apiUrl, false);
xhttp.send();
if (i < limit) {
checkVideos();
}
}, delay);
} checkVideos();
}
else if (ch || ((window.location.host == "www.nicovideo.jp") && (!window.location.pathname.startsWith("/watch/")))) {
if (ch || ((window.location.pathname.startsWith("/tag/") || (window.location.pathname.startsWith("/search/"))))) {
var delay = 200; var minViews = 50; var minScore = 5;
var skipTitlesWith = ["on vocal", "off vocal"];
if (ch) {
var videos = document.querySelectorAll(".item");
} else {
var videos = document.querySelectorAll("div.videoList ul:nth-child(2) li.item");
}
var i = -1;
function addButton(linkText, color, buttonLink, floatDirection, btnLocation) {
var btn = document.createElement("a");
var textNode = document.createTextNode(linkText);
btn.appendChild(textNode);
btn.style.backgroundColor = color;
btn.style.color = "black";
btn.style.padding = "7px 14px";
btn.style.border = "1px solid black";
btn.style.cssFloat = floatDirection;
btn.href = buttonLink;
btn.target = "_blank";
if (ch) {
document.querySelector(btnLocation).parentElement.parentElement.appendChild(btn);
} else {
document.querySelector(btnLocation).appendChild(btn);
}
}
function checkVideos() {
setTimeout(function() {
var limit;
var skip = false; i++;
let title, data, views, likes, mylists, videoId, btnLocation;
if (ch) {
limit = 19;
title = videos[i].querySelector(".title").innerText;
data = videos[i].querySelector(".counts");
views = data.querySelector(".view var").innerText.replaceAll(",", "");
mylists = data.querySelector(".mylist var").innerText.replaceAll(",", "");
videoId = videos[i].querySelector("a").href;
btnLocation = 'a[href="' + videoId + '"]';
videoId = videoId.split("/watch/")[1];
if (views < minViews || !(mylists > minScore)) {skip = true;}
} else {
limit = 31;
title = videos[i].querySelector(".itemTitle").innerText;
data = videos[i].querySelector(".itemData");
views = data.querySelector(".view .value").innerText.replaceAll(",", "");
likes = data.querySelector(".like .value").innerText.replaceAll(",", "");
mylists = data.querySelector(".mylist .value").innerText.replaceAll(",", "");
videoId = videos[i].attributes["data-video-id"].nodeValue;
btnLocation = 'li[data-video-id=' + videoId + ']';
if (views < minViews || !(mylists > minScore || likes > minScore)) {skip = true;}
}
if (skipTitlesWith.some(word => title.includes(word))) {skip = true;}
if (!skip) {
let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (xhttp.responseText == "null") {
var nicoUrl = "https://www.nicovideo.jp/watch/" + videoId;
var green = "#b0e8fc";
addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ nicoUrl, "left", btnLocation);
addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + nicoUrl, "right", btnLocation);
} else {
var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id;
var blue = "#8ef990"; addButton("Song Entry", blue, entryLink, "left", btnLocation);
}
}
};
xhttp.open("GET", apiUrl, false);
xhttp.send();
}
if (i < limit) {
checkVideos();
}
}, delay);
} checkVideos();
} else if (window.location.pathname.startsWith("/user/")) {
var videos = document.querySelectorAll(".VideoMediaObjectList a.NC-MediaObject-contents");
var limit = videos.length - 1;
var i = -1;
var delay = 500;
function addButton(linkText, color, buttonLink, floatDirection, btnLocation) {
var btn = document.createElement("a");
var textNode = document.createTextNode(linkText);
btn.appendChild(textNode);
btn.style.backgroundColor = color;
btn.style.color = "black";
btn.style.padding = "7px 14px";
btn.style.border = "1px solid black";
btn.style.position = "absolute";
btn.style.marginTop = "80px";
if (floatDirection == "right") {
btn.style.marginLeft = "100px";
}
btn.href = buttonLink;
btn.target = "_blank";
document.querySelector(btnLocation).appendChild(btn);
}
function checkVideos() {
setTimeout(function() {
i++;
var videoId = videos[i].href.split("?")[0].split("/")[4];
var btnLocation = 'a[href="https://www.nicovideo.jp/watch/' + videoId + '"]';
let apiUrl = "https://vocadb.net/api/songs/byPV?pvService=NicoNicoDouga&pvId=" + videoId;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (xhttp.responseText == "null") {
var nicoUrl = "https://www.nicovideo.jp/watch/" + videoId;
var green = "#b0e8fc";
addButton("Add", green, "https://vocadb.net/Song/Create?pvUrl="+ nicoUrl, "left", btnLocation);
addButton("Info", green, "http://nicodata.vocaloid.eu/?NicoUrl=" + nicoUrl, "right", btnLocation);
} else {
var entryLink = "https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id;
var blue = "#8ef990";
addButton("Song Entry", blue, entryLink, "left", btnLocation);
}
}
};
xhttp.open("GET", apiUrl, false);
xhttp.send();
if (i < limit) {
checkVideos();
}
}, delay);
} checkVideos();
}
} else if (["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"].indexOf(window.location.host) !== -1) {
var videoUrl = "";
if (window.location.host === "www.youtube.com") {
videoUrl = window.location.href.split("&")[0];
} else {
videoUrl = window.location.href.split("?")[0];
}
var pvsApiUrl = "https://vocadb.net/api/pvs?getTitle=false&pvUrl=";
var pvInfo = new XMLHttpRequest();
pvInfo.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var service = JSON.parse(pvInfo.responseText).service;
var videoID = JSON.parse(pvInfo.responseText).pvId;
checkDB(service, videoID);
} else if (this.status === 400) {
alert("Video ID not found for " + videoUrl);
this.onreadystatechange = null;
}
};
pvInfo.open("GET", pvsApiUrl + videoUrl, true);
pvInfo.send();
function checkDB(service, videoID) {
var apiUrl = "https://vocadb.net/api/songs/byPV?pvService=" + service + "&pvId=" + videoID;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (xhttp.responseText != "null") {
window.location.assign("https://vocadb.net/S/" + JSON.parse(xhttp.responseText).id);
} else {
window.open("https://vocadb.net/Song/Create?pvUrl=" + videoUrl);
}
}
};
xhttp.open("GET", apiUrl, true);
xhttp.send();
}
} else {
alert("Invalid URL");
return;
}
})();
@Susko3
Copy link

Susko3 commented Jan 14, 2025

For youtube music support. It's free as the url formats are the same, and vocadb already supports it.

Test URLs:

diff --git "a/.\\old.txt" "b/.\\new.txt"
index 3ea4712..b81402c 100644
--- "a/.\\old.txt"
+++ "b/.\\new.txt"
@@ -182,9 +182,9 @@ javascript:(
             }, delay);
           } checkVideos();
         } 
-      } else if (["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"].indexOf(window.location.host) !== -1) {
+      } else if (["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "music.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"].indexOf(window.location.host) !== -1) {
         var videoUrl = ""; 
-        if (window.location.host === "www.youtube.com") {
+        if (window.location.host === "www.youtube.com" || window.location.host === "music.youtube.com") {
           videoUrl = window.location.href.split("&")[0];
         } else {
           videoUrl = window.location.href.split("?")[0];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment