Skip to content

Commit

Permalink
Merge pull request #4 from pantyetta/bug-5skip-button
Browse files Browse the repository at this point in the history
たまに機能しなくなる問題の修正
  • Loading branch information
pantyetta authored Dec 9, 2023
2 parents dc08d60 + e8e67ab commit 7a7648b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# auto skip ads
youtube広告を自動でスキップします.
機能は以上です.
- 15-30程度の広告のスキップボタンを自動で押します.
- スキップ不能の広告を16倍で再生します
- スキップ不能の広告をスキップします

**広告自体のブロックはしません**

## install

### store (推奨)
[chromewebstoreからinstall](https://chromewebstore.google.com/detail/auto-skip-ads/bladpfbfkeddfhdojdjcopkejlmgapla)からインストール.
### Store (推奨)
[Chrome Webstore](https://chromewebstore.google.com/detail/auto-skip-ads/bladpfbfkeddfhdojdjcopkejlmgapla)からインストール.

### self
1. cloneかzipをダウンロードする
1. [最新版のzip](https://github.com/pantyetta/autoskip-ads/releases)をダウンロードする
2. [拡張機能ページにアクセスする](chrome://extensions/)
3. 右上ののdeveloper modeを有効にする
4. パッケージ化されていない拡張機能を読み込む を利用する
29 changes: 20 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ const skipAds = (tabId) => {
};

const $player = document.getElementById('movie_player');
const video = document.querySelector('video');

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

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

video.currentTime = video.duration;
console.log("skip container");
if($skip_container == null || !$skip_container.children.length) return;

const observer = new MutationObserver(() => {
const $skip_button = document.getElementsByClassName('ytp-ad-skip-button-modern ytp-button')[0] || null;
Expand All @@ -28,8 +24,14 @@ const skipAds = (tabId) => {

observer.disconnect();
});

observer.observe($skip_container, config);

const video = document.querySelector('video');
try {
video.currentTime = video.duration;
console.log('skip ads');
} catch (error) {}

});
playerObserver.observe($player, config);
},
Expand All @@ -39,17 +41,26 @@ const skipAds = (tabId) => {

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

chrome.webNavigation.onCommitted.addListener((details) => {
if (details.transitionType === 'reload') {
chrome.storage.session.remove([details.tabId.toString()]);
console.log("remove script");
}
}, {url: [{urlMatches : 'https://www.youtube.com/*'}]});

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
const pattern = /^https:\/\/(www\.)?youtube\.com\/.+/
if(tab.url.match(pattern) && changeInfo.status === 'complete'){

chrome.storage.session.get([tabId.toString()]).then((result) => {
if(isEmpty(result)){
console.log("insert script");
skipAds(tabId);
}
});

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

0 comments on commit 7a7648b

Please sign in to comment.