2017-09-24 92 views
-1

有沒有什麼辦法可以禁用YouTube「上一個下一個」或自動播放功能完全使用腳本或Firefox的附加?請注意名稱「自動播放」是混淆。我具體指的是在當前視頻播放結束後播放「建議」視頻的功能。該功能經常陷入循環,無限重複同樣的兩個視頻。另外,當我正在視頻下面寫評論時,它通常播放下一個視頻。最近的UI更改打破了我一直用來完成此任務的附加功能。啓用Cookie是不是我的選擇,因爲當時我有兩個不愉快的選擇之間進行選擇:腳本或插件禁用YouTube的「上一個下一個」/自動播放功能

  1. 保持餅乾和處理與污染聯繫到當前視頻的側面侵入「推薦」的視頻。

  2. 處理這個非常實施的功能,該功能似乎專門用於從用戶提取廣告收入。

我不相信,這個線程是重複的,因爲我不知道禁用最近UI更改後自動播放功能(在GitHub上,火狐約廣泛搜索任何現有的腳本:插件和谷歌)。如果腳本符合兩個條件,這將非常有幫助。

  1. 它不依賴於一個簡單的解決方案,例如在視頻結束前1秒暫停視頻。
  2. 在YouTube再次更改其界面後,它仍然有效。

下面是一個與我在更新之前使用的腳本類似的腳本,但現在已被破壞。

(function() { 
'use strict'; 
function removeAPUN() { 
    var autoplaybar = document.getElementsByClassName('autoplay-bar')[0]; 
    if (autoplaybar) { 
     autoplaybar.removeAttribute('class'); 
     document.getElementsByClassName('checkbox-on-off')[0].remove(); 
    } 
} 
window.addEventListener('readystatechange', removeAPUN, true); 
window.addEventListener('spfdone', removeAPUN); 

}());

提前致謝!

+0

[這個腳本](https://greasyfork.org/en/scripts/32159-youtube-disable-suggested-autoplay/code)爲我工作。 – wOxxOm

回答

0

你說完全禁用該功能,所以我不確定以下是100%你需要什麼,但也許它有幫助。

下不斷尋找「禁用自動播放」按鈕,直到它的存在,然後單擊它,如果它當前設置爲活動:點擊按鈕

setTimeout(disable_autoplay, 1000); 

function disable_autoplay(){ 
    // Try to get the toggle button 
    var toggle_button = document.getElementById("toggle"); 
    if (toggle_button){ 
     if (toggle_button.hasAttribute("checked")){ 
      // If it is checked, click it to disable autoplay 
      toggle_button.click(); 
      // Retry one more time to make sure it stays disabled 
      setTimeout(disable_autoplay, 5000); 
     } 
    } else { 
     // Not found, retry 
     console.log("Retrying in 1s"); 
     setTimeout(disable_autoplay, 1000); 
    } 
} 

後它重試一次,我我不確定這是否是必需的,但是當我手動禁用自動播放功能時,它有時會稍後切換回來,所以這實際上只是爲了確保它保持關閉狀態。

0

這是適合我個人使用的解決方案,適用於新老版本的YouTube佈局。可能有一個更簡單的解決方案,但這個不使用間隔計時器,以避免電池消耗。

function fixAutoplayNext() 
{ 
    let autoplay = document.getElementsByClassName("autoplay-bar")[0]; 
    if (autoplay) // old layout 
    { 
     let check = document.querySelector("#autoplay-checkbox-label > .checked"); 
     let input = document.getElementById("autoplay-checkbox") || document.getElementById("toggle"); 
     if (check && input) 
     { 
      if (parseInt(window.getComputedStyle(check).width, 10) > 0) 
      { 
       input.click(); 
      } 
     } 
     // Removing the switch is optional, but I don't see a reason to leave it around. 
     autoplay.parentNode.removeChild(autoplay); 
    } 
    else // new layout 
    { 
     autoplay = document.getElementById("head"); 
     if (autoplay) 
     { 
      let toggler = document.getElementById("toggle"); 
      if (toggler && toggler.hasAttribute("checked")) 
      { 
       //toggler.click(); 
       toggler.removeAttribute("checked"); 
       toggler.dispatchEvent(new Event("change")); 
      } 
      // Removing the switch is optional, but I don't see a reason to leave it around. 
      autoplay.parentNode.removeChild(autoplay); 
     } 
    } 
} 

fixAutoplayNext(); 

// Youtube loads pages entirely using Ajax. Listening for a video to load is enough for now. 
document.addEventListener("loadstart", function(e) { 
    if (e.target instanceof window.HTMLMediaElement) 
    { 
     window.setTimeout(fixAutoplayNext, 25); 
    } 
}, true); 
相關問題