Skip to content

Instantly share code, notes, and snippets.

@jdehorty
Created July 18, 2021 21:30
Show Gist options
  • Save jdehorty/687984839ecc7303b534985e824c0333 to your computer and use it in GitHub Desktop.
Save jdehorty/687984839ecc7303b534985e824c0333 to your computer and use it in GitHub Desktop.
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict'; // https://developer.chrome.com/extensions/runtime#event-onInstalled
chrome.runtime.onInstalled.addListener(function (details) {
if (details.previousVersion) {
return;
} else {
// set new user sid for referrals
// send to welcome page where the webpage also checks if they were sent by a referral
window.open('https://summarybox.com/welcome', '_blank');
}
});
var contexts = ["link"];
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i];
var title = "Generate Summary";
var id = chrome.contextMenus.create({
"title": title,
"contexts": [context],
"onclick": genericOnClick
});
}
function genericOnClick(info, tab) {
chrome.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
"functionToInvoke": "display",
"info": info,
"invokeMethod": "link_option"
});
});
} // when a user clicks on the menu icon next to url bar.
chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
"functionToInvoke": "display",
"info": {
linkUrl: null
},
"invokeMethod": "browser_action"
});
});
}); // tracking when page closes
chrome.tabs.onRemoved.addListener(function (tabid, removed) {
chrome.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
"functionToInvoke": "tab_close"
});
});
}); // https://stackoverflow.com/questions/13806307/how-to-insert-content-script-in-google-chrome-extension-when-page-was-changed-vi
let currentlyNavigating = false;
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
// Because for Youtube, when a user navigates to a new video for the first time, it always does 3 quick consecutive navigations for some reason under the hood.
// The solution for now is just to put a timer so that we only count a navigation if it happens after some buffer time like a second or two.
// if (currentlyNavigating) return
// currentlyNavigating = true
// We're using a timeout before sending message to wait for the window.location.href to change in content script
// It uses the new URL to compare to past URLS that it has already rendered.
// Also, one thing I noticed is that going from the homepage of Youtube to a video takes longer for the URL to change.
// If we don't wait long enough, it will try to find the subscribe button, to put the auto button next to but not be able to find the subscribe button.
setTimeout(function () {
chrome.tabs.query({
"active": true,
"currentWindow": true
}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
"functionToInvoke": "reinit",
"url": details.url
});
currentlyNavigating = false;
});
}, 1000);
});
chrome.runtime.setUninstallURL('https://summarybox.typeform.com/to/xu9aee');
},{}]},{},[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment