Skip to content

Commit

Permalink
Merge pull request #2 from pantyetta/disable-x16-skip-all
Browse files Browse the repository at this point in the history
Disable x16 skip all
  • Loading branch information
pantyetta authored Nov 30, 2023
2 parents 2236143 + 025120f commit dc08d60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 16 additions & 6 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const skipAds = (tabId) => {

const playerObserver = new MutationObserver(() => {
const $skip_container = document.getElementsByClassName("video-ads ytp-ad-module")[0] || null;
if(!$skip_container.children.length) {
video.playbackRate = 1;
return;
}
if(!$skip_container.children.length) return;

video.playbackRate = 16;
if(video.currentTime == video.duration) return;

video.currentTime = video.duration;

const observer = new MutationObserver(() => {
const $skip_button = document.getElementsByClassName('ytp-ad-skip-button-modern ytp-button')[0] || null;
if($skip_button == null) return;
$skip_button.click();
console.log('skip ads click');

observer.disconnect();
});
Expand All @@ -37,9 +37,19 @@ const skipAds = (tabId) => {
}


const isEmpty = (obj) => {
return !Object.keys(obj).length;
}

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
const pattern = /^https:\/\/(www\.)?youtube\.com\/.+/
if(tab.url.match(pattern) && changeInfo.status === 'complete'){
skipAds(tabId);
chrome.storage.session.get([tabId.toString()]).then((result) => {
if(isEmpty(result)){
skipAds(tabId);
}
});

chrome.storage.session.set({ [tabId]: true });
}
})
6 changes: 4 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "auto skip ads",
"version": "1.0.3",
"version": "1.0.4",
"description": "youtube広告をブロックせずにスキップします",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
Expand All @@ -13,7 +14,8 @@
"permissions": [
"activeTab",
"tabs",
"scripting"
"scripting",
"storage"
],
"host_permissions": [
"https://www.youtube.com/*",
Expand Down

0 comments on commit dc08d60

Please sign in to comment.