diff --git a/README.md b/README.md index 42e21ca..114fa33 100644 --- a/README.md +++ b/README.md @@ -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. パッケージ化されていない拡張機能を読み込む を利用する diff --git a/background.js b/background.js index a351528..e4793f4 100644 --- a/background.js +++ b/background.js @@ -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; @@ -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); }, @@ -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 }); } -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 14f9fa9..22ea514 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "auto skip ads", - "version": "1.0.4", + "version": "1.0.5", "description": "youtube広告をブロックせずにスキップします", "manifest_version": 3, "background": { @@ -15,7 +15,8 @@ "activeTab", "tabs", "scripting", - "storage" + "storage", + "webNavigation" ], "host_permissions": [ "https://www.youtube.com/*",