javascript - YouTube Auto-Like script not working until I refresh -


i not author of code , have no prior experience code, credits go original author, joesimmons. problem having code works fine, works when either refresh youtube video page or go link directly, google search. i'd know if able me out in fixing issue. of course, i'm not experienced @ simplest of scripts. thankyou in advance! apologise if tagging on question wrong, said earlier i'm clueless.

// ==userscript== // @name           youtube auto-like videos // @namespace      http://userscripts.org/users/23652 // @description    automatically clicks 'like' button // @include        http://*.youtube.com/watch*v=* // @include        http://youtube.com/watch*v=* // @include        https://*.youtube.com/watch*v=* // @include        https://youtube.com/watch*v=* // @copyright      joesimmons // @version        1.1.02 // @license        gpl version 3 or later version; http://www.gnu.org/copyleft/gpl.html // @require        https://greasyfork.org/scripts/1884-gm-config/code/gm_config.js?version=4836 // @require        https://greasyfork.org/scripts/1885-joesimmons-library/code/joesimmons'%20library.js?version=7915 // @require        https://greasyfork.org/scripts/2104-youtube-button-container-require/code/youtube%20-%20button%20container%20(@require).js?version=5493 // @grant          gm_getvalue // @grant          gm_setvalue // @grant          gm_registermenucommand // ==/userscript==  /* changelog      1.1.02 (6/7/2015)         - fixed script      1.1.01 (3/14/2015)         - fixed bug of liking videos when username list empty      1.1.0 (3/13/2015)         - added new option allow auto-liking of videos subscribed channels      1.0.40 (3/12/2015)         - adapted youtube changing like/dislike buttons' classes      1.0.39 (1/26/2015)         - changed timeout of script waits real 30 seconds, not x amout of intervals             should more accurate, on weaker computers browsers freeze , intervals overlap      1.0.38 (1/19/2015)         - adapted page change (different class name of author link)      1.0.37 (9/8/2014)         - adapted new youtube style         - fixed issue channel names punctuation in them not getting "liked"      1.0.36 (12/17/2013)         - added user-script command options      1.0.35 (12/14/2013)         - started using youtube button container         - made code more readable using jsl , @requires      1.0.34         - added compatibility opera & chrome  */    (function () {     'use strict';      var t = 0, tmax = 30,         spaceregex = /([ \t]+)|(\n[ \r\n\r]+\n)/g,         newlineregex = /\n/g,         uregex = /\/user\/(\w+)/i,         spaces = /\s+/g,         rblank = /^\s*$/,         rvideoid = /[&?]v=([a-za-z0-9-_]+)/,         rsubscribed = /^true$/i,         runclicked = /like-button-renderer-(dis)?like-button-unclicked/,         intv, pass, auto_like_list, timestart, likesubscribedchannels;      // click joesimmons     function click(element, type) {         var eventobject = document.createevent('mouseevents');             element = typeof element === 'string' ? document.getelementbyid(element) : element;             type =  typeof type === 'string' ? type : 'click';          if (element.isjsl === true) {             element = element[0];         }          if (element) {             eventobject.initmouseevent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);             element.dispatchevent(eventobject);         }     }      function waitforshare() {         var sharebox = jsl('#watch-action-panels'),             shareclosebutton = jsl('#action-panel-dismiss');          // close share box after appears         if (sharebox.visible) {             window.settimeout(click, 750, shareclosebutton);         } else {             window.settimeout(waitforshare, 250);         }     }      function ispressed(e) {         return e.attribute('class').match(runclicked) == null;     }      function dolike() {         var author = jsl('#watch7-user-header .yt-user-info a.g-hovercard'),             = jsl('#watch8-sentiment-actions button.like-button-renderer-like-button'),             dislike = jsl('#watch8-sentiment-actions button.like-button-renderer-dislike-button'),             subbox = jsl('#watch7-subscription-container span .yt-uix-subscription-button'),             authorhref = '',             authortext = '',             usernamehref = '',             usernametext = '';          // quit trying auto-like after 15 seconds         if ( (date.now() - timestart) >  15000) {             jsl.clearinterval(intv);             // throw new error('warning: 30 seconds elapsed; failed auto-like video id: ' + window.location.href.match(rvideoid)[1] );         }          // check if author link, button, or sub box don't exist         if (!author.exists || !like.exists || !subbox.exists) {             throw new error('error: either author link, button, or sub box not exist.');         }          // grab author text , href         authortext = author.text();         authorhref = author.prop('href');          // figure out username of video author         if ( authorhref.match(uregex) ) {             usernamehref = authorhref.match(uregex)[1];         }         usernametext = authortext.replace(spaces, '');          // try click         if ( gm_config.get('auto') === true || ( auto_like_list.match(rblank) == null && ( usernamehref.match(pass) || usernametext.match(pass) ) ) ||                (likesubscribedchannels === true && subbox.attribute('data-is-subscribed').match(rsubscribed) ) ) {             if ( !ispressed(like) && !ispressed(dislike) ) {                 window.settimeout(click, 750, like);                 jsl.clearinterval(intv);                  // if enabled, close "share" box appears after liking video                 if (gm_config.get('closeshare') === true) {                     window.settimeout(waitforshare, 3500);                 }             }         }     }      // make sure page not in frame     if (window.frameelement || window !== window.top) { return; }      if (typeof gm_registermenucommand === 'function') {         gm_registermenucommand('youtube auto-like options', gm_config.open);     }      gm_config.init('youtube auto-like options', {         auto : {             section : ['main options'],             label : 'auto-like videos?',             type : 'checkbox',             'default' : true,             title : 'enabling make "like" videos'         },         closeshare : {             label : 'auto-close share box after liking',             type : 'checkbox',             'default' : false,             title : 'enabling close share box after video gets "liked"'         },         likesubscribedchannels : {             label : 'auto-like videos subscribed channels',             type : 'checkbox',             'default' : false,             title : 'if video uploaded channel you\'re subscribed to, it'         },         list : {             section : ['specific usernames'],             label : 'list usernames of users\' videos want auto-like.',             type : 'textarea',             cols : 80,             rows : 20,             'default' : 'write usernames here separated lines',             title : 'this feature enabled if previous feature disabled.'         }     });      object.defineproperty(string.prototype, 'prepareregex', {         enumerable : false,         value : function () {             return this.replace(/[*^&$.()?+{}|\[\]\/\\]/g, '\\$&');         }     });      auto_like_list = gm_config.get('list');     likesubscribedchannels = gm_config.get('likesubscribedchannels');      // convert list of channel names regular expression     pass = new regexp('(' + auto_like_list.trim().replace(spaceregex, '').prepareregex().replace(newlineregex, '|') + ')', 'i');      // run function when page loaded     jsl.runat('end', function() {         addbuttontocontainer('auto-like options', gm_config.open);          // try 'like' video 30 seconds max         window.settimeout(function () {             timestart = date.now();              intv = jsl.setinterval(function () {                 dolike();             }, 750);         }, 1000);     });  }()); 


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -