Instantly share code, notes, and snippets.

Embed
What would you like to do?
// For readability - copy-pasting this one won't work. Use the minified code below instead.
function vdb() {
// http://wiki.vocadb.net/wiki/31/media-video-services-supported-by-vocadb
whitelist = ["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"];
if (whitelist.indexOf(window.location.host) === -1) {
alert("Invalid URL");
return;
}
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
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; // prevents duplicate alerts
}
};
pvInfo.open("GET", pvsApiUrl + videoUrl, true);
pvInfo.send();
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
function checkDB(service, videoID) {
var apiUrl = "https://vocadb.net/api/songs?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();
}
}
javascript:(function() {whitelist = ["piapro.jp", "vimeo.com", "soundcloud.com", "www.youtube.com", "www.nicovideo.jp", "www.bilibili.com", "www.creofuga.net"]; if (whitelist.indexOf(window.location.host) === -1) {alert("Invalid URL"); return;} 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?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();}})()
@Shiroizu

This comment has been minimized.

Show comment
Hide comment
@Shiroizu

Shiroizu Nov 27, 2017

Bookmarklet script for indexing songs from various media services to VocaDB.

If the video (song) already exists on the database, the song entry page will be displayed, replacing the current tab. *
If the entry doesn't exist, the song submit page opens as a new tab with pre-filled video URL -field (this requires browser pop-up permissions for the video sites).

* To preserve the current tab (when entry found), change "window.location.assign" to "window.open".

Owner

Shiroizu commented Nov 27, 2017

Bookmarklet script for indexing songs from various media services to VocaDB.

If the video (song) already exists on the database, the song entry page will be displayed, replacing the current tab. *
If the entry doesn't exist, the song submit page opens as a new tab with pre-filled video URL -field (this requires browser pop-up permissions for the video sites).

* To preserve the current tab (when entry found), change "window.location.assign" to "window.open".

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