I want to be able to see only certain channels on youtube, so I try to get the name of the youtube channel on Tampermonkey (Javascript) and move the code to close the window if it doesn't fit the whitelist.
I wanted to divert the tampermonkey cord because it was rolling, but it didn't work properly.
With the code below,
var testString=$(".yt-user-info")[0].firstElementChild.innerHTML;
does not work, and the code stops there (no errors in particular)
//==UserScript==
// @name Youtube Whitelist Script
// @namespace http://tampermonkey.net/
// @version0.1b
// @description This script will remove the content from YouTube videos. Ignores whitelisted content
// @author Louis Vaught
// @ match https://www.youtube.com/watch*
// @copyright2017, Louis Vaught
// @require https://code.jquery.com/jquery-latest.js
// ==/UserScript==
var$=window.jQuery;
///////////////////////
// EDIT WHITELIST HERE:
///////////////////////
varwhitelist=[
'The Backyard Scientist',
'Cody\'sLab',
"The Slo Mo Guys".
];
// Make sure to match the name exact. Not case-sensitive.
//////////////////////////
// String Search Function:
//////////////////////////
function searchStringInArray(str, strArray){
for(varj=0;j<strArray.length;j++){
vartestStr=strArray[j].toLowerCase();
varmatchStr=str.toLowerCase();
if(testStr.match(matchStr)) return j;
}
return-1;
}
////////////////////
// Main Script Body:
////////////////////
$(document).ready(function(){
alert("main kokokara")
// Find the channel name on the page
vartestString=$(".yt-user-info")[0].firstElementChild.innerHTML;
// vartestString="hogehoge"
alert(testString)
// Search for the channel name in the array
varsearchVal=searchStringInArray(testString, whitelist);
// If the channel isn't present, then delete content and error out:
if(searchVal==-1){
$("#page-container").remove();
alert("This channel is not on the YouTube whitelist!");
}
});
At the top of the cord
//@require http://code.jquery.com/jquery-latest.js
var$=window.jQuery;
I think I can use jQuery (no error) because it is specified as
I may not be able to use it.
I would appreciate it if you could let me know if there are any mistakes in the code or how to use jQuery.
Thank you for your cooperation.
I'm sorry that I didn't mention that it's multi-post.
It has been resolved on the following website.
https://teratail.com/questions/320591#
© 2024 OneMinuteCode. All rights reserved.