austencm / youtube-auto-like

Chrome extension that automatically likes videos from your subscribed channels.
MIT License
163 stars 53 forks source link

Not working in Google Chrome, Shows Errors. #37

Closed BG1959 closed 4 years ago

BG1959 commented 4 years ago

It does not work on any of the three settings and throws errors every time I try it. I have disabled other apps, restarted Chrome, reinstalled Chrome, and Auto Like, nothing works. Here is the error: 1 !function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(n,s,function(e){return t[e]}.bind(null,s));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=13)}({0:function(t,e,i){"use strict";i.d(e,"a",(function(){return n}));class n{constructor(t){this.defaults=t,this.get=this.get.bind(this)}get(){return new Promise((t,e)=>{chrome.storage.sync.get({options:this.defaults},e=>t(e.options))})}set(t){return new Promise((e,i)=>{chrome.storage.sync.set({options:t},e)})}}},1:function(t,e,i){(function(e){t.exports={NODE_ENV:"production",PORT:e.env.PORT||3e3,DEBUG:!1}}).call(this,i(2))},13:function(t,e,i){"use strict";i.r(e);var n=i(1),s=i.n(n);class o{constructor(t){this.options=t,this.init=this.init.bind(this),this.reset=this.reset.bind(this),this.attemptLike=this.attemptLike.bind(this)}reset(){this.dom={}}waitForButtons(t){this.dom.like=this.dom.like||document.querySelector(".like-button-renderer-like-button-unclicked"),this.dom.dislike=this.dom.dislike||document.querySelector(".like-button-renderer-dislike-button-unclicked"),this.dom.like&&this.dom.dislike?t():setTimeout(()=>this.waitForButtons(t),1e3)}attemptLike(){this.waitForButtons(()=>{this.isVideoRated()||"subscribed"===this.options.like_what&&!this.isUserSubscribed()||(this.dom.like.click(),this.isVideoRated()||setTimeout(this.attemptLike,1e3))})}isVideoRated(){return this.dom.like.classList.contains("hid")||this.dom.dislike.classList.contains("hid")}isUserSubscribed(){return document.querySelector(".yt-uix-subscription-button").classList.contains("hover-enabled")}init(){if(!this.options.disabled&&"none"!==this.options.like_what)if(this.reset(),"timed"!==this.options.like_when)this.attemptLike();else{const t=document.querySelector(".video-stream"),{duration:e}=t,i=()=>{(t.currentTime>=120||t.currentTime>=e)&&(this.attemptLike(),t.removeEventListener("timeupdate",i))};t.addEventListener("timeupdate",i)}}}const r={iconLike:'g path[d="M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-1.91l-.01-.01L23 10z"]',iconDislike:'g path[d="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v1.91l.01.01L1 14c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z"]',subscribeButton:"ytd-watch-flexy ytd-subscribe-button-renderer > paper-button, ytg-subscribe-button .subscribed"};class c{constructor({options:t,log:e}){this.options=t,this.log=e||(()=>{}),this.cache={},this.init=this.init.bind(this),this.reset=this.reset.bind(this),this.attemptLike=this.attemptLike.bind(this)}stop(){this.log("stopped"),"function"==typeof this.onStop&&this.onStop()}reset(){this.cache={}}waitForButtons(t){const e=document.querySelector(r.iconLike),i=document.querySelector(r.iconDislike);e&&i?(this.cache.likeButton=e.closest("yt-icon-button, paper-icon-button"),this.cache.dislikeButton=i.closest("yt-icon-button, paper-icon-button"),this.log("...buttons ready"),t()):setTimeout(()=>this.waitForButtons(t),1e3)}waitForVideo(t){this.log("waiting for video..."),this.video=document.querySelector(".video-stream"),this.video?(this.log("...video ready"),t()):setTimeout(()=>this.waitForVideo(t),1e3)}isVideoRated(){return this.cache.likeButton.classList.contains("style-default-active")&&!this.cache.likeButton.classList.contains("size-default")||this.cache.dislikeButton.classList.contains("style-default-active")}isUserSubscribed(){const t=this.cache.subscribeButton||document.querySelector(r.subscribeButton);return!!t&&(!(!t.hasAttribute("subscribed")&&!t.classList.contains("subscribed"))&&(this.cache.subscribeButton=t,!0))}isAdPlaying(){return this.video&&["ad-showing","ad-interrupting"].every(t=>this.video.closest(".html5-video-player").classList.contains(t))}attemptLike(){this.log("waiting for buttons..."),this.waitForButtons(()=>this.isVideoRated()?(this.log("video already rated"),this.stop()):"subscribed"!==this.options.like_what||this.isUserSubscribed()?(this.cache.likeButton.click(),this.log("like button clicked"),void this.stop()):(this.log("user not subscribed"),this.stop()))}init(){if(this.log("liker initialized"),this.options.disabled||"none"===this.options.like_what)return this.log("liker is disabled"),this.stop();switch(this.reset(),this.options.like_when){case"timed":return this.waitForVideo(()=>{const{video:t}=this,e=i=>{this.isAdPlaying()||(t.currentTime>=120||t.currentTime>=t.duration)&&(this.attemptLike(),t.removeEventListener("timeupdate",e))};t.addEventListener("timeupdate",e)});case"percent":return this.waitForVideo(()=>{const{video:t}=this,e=i=>{this.isAdPlaying()||t.currentTime/t.duration>=.5&&(this.attemptLike(),t.removeEventListener("timeupdate",e))};t.addEventListener("timeupdate",e)});default:return this.attemptLike()}}}var u=i(0);const a=new class{constructor(){this.messages=[],this.log=this.log.bind(this),this.save=this.save.bind(this),this.log((new Date).toDateString()),this.log(navigator.userAgent)}log(){const t=Array.from(arguments).join(" ");this.messages.push(t),s.a.DEBUG&&console.log(%c[DEBUG] %c${t},"font-style: italic","")}save(t){return new Promise((t,e)=>{chrome.storage.sync.set({log:this.messages.join("\n")},t)})}},d=!document.body.id,l=window.location.href.indexOf("//gaming.youtube")>-1;a.log("YouTube variant:",l?"gaming":d?"material":"classic"),a.log("navigated:",window.location.href),["yt-navigate","yt-navigate-finish","yt-page-data-updated"].forEach(t=>{document.querySelector("ytd-app").addEventListener(t,e=>{a.log("event:",e.type),"yt-navigate-finish"===t&&a.log("navigated:",window.location.href)})});setTimeout(()=>{const t=new u.a({like_what:"subscribed",like_when:"instantly",disabled:!1});a.log("loading options..."),t.get().then(t=>{if(a.log("...options loaded",(${function(t){return Object.keys(t).map(e=>${encodeURIComponent(e)}: ${encodeURIComponent(t[e])}).join(encodeURI(","))}(t)})),d){const e=new c({options:t,log:a.log});e.onStop=a.save,s.a.DEBUG&&(window.Liker=e),e.init();const i=l?"ytg-app":"ytd-app";document.querySelector(i).addEventListener("yt-page-data-updated",e.init)}else{const e=new o(t);e.init(),window.addEventListener("spfdone",e.init)}})},0)},2:function(t,e){var i,n,s=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function c(t){if(i===setTimeout)return setTimeout(t,0);if((i===o||!i)&&setTimeout)return i=setTimeout,setTimeout(t,0);try{return i(t,0)}catch(e){try{return i.call(null,t,0)}catch(e){return i.call(this,t,0)}}}!function(){try{i="function"==typeof setTimeout?setTimeout:o}catch(t){i=o}try{n="function"==typeof clearTimeout?clearTimeout:r}catch(t){n=r}}();var u,a=[],d=!1,l=-1;function h(){d&&u&&(d=!1,u.length?a=u.concat(a):l=-1,a.length&&p())}function p(){if(!d){var t=c(h);d=!0;for(var e=a.length;e;){for(u=a,a=[];++l<e;)u&&u[l].run();l=-1,e=a.length}u=null,d=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===r||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{n(t)}catch(e){try{return n.call(null,t)}catch(e){return n.call(this,t)}}}(t)}}function m(t,e){this.fun=t,this.array=e}function f(){}s.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)e[i-1]=arguments[i];a.push(new m(t,e)),1!==a.length||d||c(p)},m.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=f,s.addListener=f,s.once=f,s.off=f,s.removeListener=f,s.removeAllListeners=f,s.emit=f,s.prependListener=f,s.prependOnceListener=f,s.listeners=function(t){return[]},s.binding=function(t){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(t){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}}});

LinuxSteely commented 4 years ago

Also having the issue. With Chrome's pretty print feature I narrowed it down to document.querySelector("ytd-app") being null. I checked after watching a video for a while and it was still null. Best guess is YouTube decided to change their site again.

austencm commented 4 years ago

Interesting...I can't reproduce this. I just published a v2.5.0. It's probably related. Could you guys do me a favor and click on the report link in the options? It will create an issue with a log from the last time the extension ran.

LinuxSteely commented 4 years ago

So I tried to do that but it looks like you have another issue... "no log found". I submitted the issue anyway just for that. I manually made a log but I'm not sure if this will help you. www.youtube.com-1571374821786.log

The error still shows at ["yt-navigate", "yt-navigate-finish", "yt-page-data-updated"].forEach(t=>{ document.querySelector("ytd-app").addEventListener(t, e=>{ u.log("event:", e.type), "yt-navigate-finish" === t && u.log("navigated:", window.location.href) } ) }

austencm commented 4 years ago

If an error shuts it down prematurely then the log won’t get saved. Definitely need to improve error catching.

Could you paste the entire HTML of the first YouTube page you see this on and let me know the URL?

LinuxSteely commented 4 years ago

It's happening on all pages. Here is the one I'm attaching: https://www.youtube.com/watch?v=pYDXeQ4zVN4

I took out my username and email just in case... I'm paranoid.

P.S. apparently I can't attach html so I just changed it to txt lol

Lawful Masses Friday Comment Review #1 - October 18, 2019 - YouTube.txt

LinuxSteely commented 4 years ago

I cannot for the life of me figure out why "ytd-app" does not exist with only this extension enabled but it does in incognito mode... Going to sleep now.

austencm commented 4 years ago

It looks like you're using an old version of YouTube...are you using any other extensions that affect YouTube?

LinuxSteely commented 4 years ago

You are correct. It's easier to think after some sleep. :) I use "Improve YouTube! (Open-Source for YouTube)" and one of the settings I changed was to use the old version of YouTube. It was so long ago that I forgot. I'm assuming which version you use is saved as a cookie or something, which would explain why disabling the Improve YouTube extension didn't change me back to the new YouTube. Your extension does work if I change back to the new version of YouTube but it would be nice if you could get the extension working on the old version.

Edit: It was working before v2.5.0

austencm commented 4 years ago

Ah ok, glad we got that figured out. I didn’t really decide to drop support for old YT or anything. Just haven’t been testing it. I’ll see how easy a fix is, but since old YT has been obsolete for a few years now support for it is low priority.

austencm commented 4 years ago

This should be fixed in v2.5.2!