Skip to content

Commit

Permalink
Merge pull request #79 from GoogleChromeLabs/mv3
Browse files Browse the repository at this point in the history
Migrate to manifest version 3
  • Loading branch information
beaufortfrancois committed Sep 15, 2022
2 parents 20288da + 38ef664 commit f6c50ad
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 32 deletions.
32 changes: 10 additions & 22 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

if (!document.pictureInPictureEnabled) {
chrome.browserAction.setTitle({ title: 'Picture-in-Picture NOT supported' });
} else {
chrome.browserAction.onClicked.addListener(tab => {
chrome.tabs.executeScript({ file: 'script.js', allFrames: true });
chrome.action.onClicked.addListener((tab) => {
chrome.storage.sync.get({ optOutAnalytics: false }, (results) => {
const files = results.optOutAnalytics
? ["script.js"]
: ["script.js", "ga.js"];
chrome.scripting.executeScript({
target: { tabId: tab.id, allFrames: true },
world: "MAIN",
files,
});
});
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-134864766-1']);

chrome.runtime.onMessage.addListener(data => {
if (data.message === 'enter')
_gaq.push(['_trackPageview']);
});

chrome.storage.sync.get({ optOutAnalytics: false }, results => {
if (results.optOutAnalytics) {
return;
}
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
});
Loading

0 comments on commit f6c50ad

Please sign in to comment.