Skip to content

Instantly share code, notes, and snippets.

@Shiroizu
Last active June 14, 2024 11:18
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;
}
})();
@Shiroizu
Copy link
Author

Shiroizu commented Mar 31, 2020

Bookmarklet script with two purposes (depends on the current URL):

1) Quickly finding the song entry page from the video page (NicoNico, Youtube, SoundCloud, etc):

  • If the song entry page already exists on the database, it will be displayed replacing the current tab.
    (if opening in a new tab is preferred, change the line "window.location.assign" to "window.open")

  • If the entry doesn't exist, a song submit page opens as a new tab with pre-filled video URL -field (this requires browser pop-up permissions for the video sites).

2) Helping with browsing the vocaloid-tag (works with any tag) on NicoNicoDouga: https://www.nicovideo.jp/tag/VOCALOID?sort=f&order=d

The script adds buttons below the video links (song entry or add+info) if the view count and the mylist count is more than specified.

pic

3) Also works on the NND search pages, artist mylist pages and artist video pages.

4) Also works on nicolog user pages

5) Also works on https://ch.nicovideo.jp/{x}/video -pages

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