Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Just go to http://www.youtube.com/all_comments?v=I6gYpSCJ99Y.
- On that page copy this bookmarklet on the url bar:
- javascript:(function(){var script=document.createElement("script");script.src="http://blackboard.altervista.org/extractUserFromYoutubeComments.js";document.head.appendChild(script)})();
- Alternatively, open a developer console on the page (CTRL+SHIFT+J on Chrome, CTRL+SHIFT+K on Firefox) and write:
- (function(){var script=document.createElement("script");script.src="http://blackboard.altervista.org/extractUserFromYoutubeComments.js";document.head.appendChild(script)})();
- This should work on every youtube all comments page.
- The script get how many votes each user has and then give them one random number for each vote.
- The user with the highest random number wins.
- You can read the code below or at the location specified in the bookmarklet.
- */
- var logic = function(){
- var authors = [],
- votes = {},
- comments = [],
- op = $('.grayText:contains("From:")').next().text().toLowerCase();
- //getting all the authors
- $('.author>a').each(function(){
- var author = $(this).text().toLowerCase();
- //the author of the comment with id x is saved in authors[x]
- authors.push(author);
- //give each unique user (but the original poster) a vote
- if (author!==op){
- votes[author] = 1;
- }
- });
- //getting all the comments
- $('.comment-text>p').each(function(i){
- var comment = $(this).text().toLowerCase();
- //for every comment, check if the one of the users is referenced
- //(and check if someone is referencing himself)
- for (user in votes){
- if (comment.indexOf(user)!==-1 && user!==authors[i-1]){
- votes[user]++;
- }
- }
- });
- //each user has a random number from 0 to 1
- //the highest one wins
- //each additional vote give one more chance
- //i.e.: 2 votes => 2 random numbers
- var globalMax = 0;
- var winningUser;
- for(user in votes){
- var max = 0;
- for (i=0; i<votes[user]; i++){
- var number = Math.random();
- if (number>max)
- max = number;
- }
- if (max>globalMax){
- globalMax = max;
- winningUser = user;
- }
- }
- alert(winningUser);
- };
- //Loading jQuery
- var script = document.createElement('script');
- script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js";
- document.head.appendChild(script);
- var done = false;
- script.onload = script.onreadystatechange = function() {
- if (!done && (!this.readyState ||
- this.readyState === "loaded" || this.readyState === "complete") ) {
- done = true;
- logic();
- script.onload = script.onreadystatechange = null;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement