Skip to content

Commit 813e553

Browse files
committed
minor fix to able to run demo in github pages
1 parent bd280d5 commit 813e553

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

popup/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ const updateTargetTab = UfsGlobal.Utils.debounce(async () => {
534534
}, 500);
535535

536536
async function initOpenInNewTab() {
537+
if (!chrome?.tabs) return;
538+
537539
let currentTab = await chrome.tabs.getCurrent();
538540
isInNewTab = currentTab != null;
539541

@@ -1010,7 +1012,7 @@ window.addEventListener("scroll", onScrollEnd);
10101012
initScrollToTop();
10111013
createTabs().then(restoreScroll);
10121014

1013-
chrome.windows.onFocusChanged.addListener((windowId) => {
1015+
chrome?.windows?.onFocusChanged?.addListener?.((windowId) => {
10141016
setTimeout(async () => {
10151017
let currentTab = await getCurrentTab();
10161018
}, 200);

scripts/smoothScroll.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ export function enableSmoothScroll() {
182182
/***********************************************
183183
* SETTINGS
184184
***********************************************/
185-
chrome.storage.sync.get(defaultOptions, function (syncedOptions) {
186-
options = syncedOptions;
187-
// it seems that sometimes settings come late
188-
// and we need to test again for excluded pages
189-
initTest();
190-
});
185+
// chrome.storage.sync.get(defaultOptions, function (syncedOptions) {
186+
// options = syncedOptions;
187+
// // it seems that sometimes settings come late
188+
// // and we need to test again for excluded pages
189+
// initTest();
190+
// });
191+
initTest();
191192
/***********************************************
192193
* INITIALIZE
193194
***********************************************/
@@ -735,11 +736,11 @@ export function enableSmoothScroll() {
735736
if (deltaY < 50) tp = true;
736737
clearTimeout(deltaBufferTimer);
737738
deltaBufferTimer = setTimeout(function () {
738-
chrome.storage.local.set({
739+
chrome?.storage?.local?.set?.({
739740
deltaBuffer: deltaBuffer,
740741
});
741742
if (!tp)
742-
chrome.storage.local.set({
743+
chrome?.storage?.local?.set?.({
743744
lastDiscreetWheel: dateNow(),
744745
});
745746
}, 1000);
@@ -755,7 +756,7 @@ export function enableSmoothScroll() {
755756
isDivisible(deltaBuffer[2], divisor)
756757
);
757758
}
758-
chrome.storage.local.get("deltaBuffer", function (stored) {
759+
chrome?.storage?.local?.get?.("deltaBuffer", function (stored) {
759760
if (stored.deltaBuffer) {
760761
deltaBuffer = stored.deltaBuffer;
761762
}
@@ -838,21 +839,21 @@ export function enableSmoothScroll() {
838839
// we check the OS for default middle mouse behavior only!
839840
let isLinux = navigator.platform.indexOf("Linux") != -1;
840841
// get global settings
841-
chrome.storage.sync.get(defaultOptions, function (syncedOptions) {
842-
options = syncedOptions;
843-
// leave time for the main script to check excluded pages
844-
setTimeout(function () {
845-
// if we shouldn't run, stop listening to events
846-
if (isExcluded && !options.middleMouse) {
847-
cleanup();
848-
}
849-
}, 10);
850-
});
842+
// chrome.storage.sync.get(defaultOptions, function (syncedOptions) {
843+
// options = syncedOptions;
844+
// // leave time for the main script to check excluded pages
845+
// setTimeout(function () {
846+
// // if we shouldn't run, stop listening to events
847+
// if (isExcluded && !options.middleMouse) {
848+
// cleanup();
849+
// }
850+
// }, 10);
851+
// });
851852
/**
852853
* Initializes the image at the reference point.
853854
*/
854855
function init() {
855-
let url = chrome.runtime.getURL("/scripts/smoothscroll_cursor.png");
856+
let url = chrome?.runtime?.getURL?.("/scripts/smoothscroll_cursor.png");
856857
img.style.background = "url(" + url + ") no-repeat";
857858
img.style.position = "fixed";
858859
img.style.zIndex = "999999999";

0 commit comments

Comments
 (0)