Skip to content

Commit

Permalink
prepare next version with global javascript toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
maximelebreton committed Nov 1, 2024
1 parent 514bda9 commit 4adc680
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/entry/background/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,28 @@ export const handleRequestTabsPermission = (callback: (granted: boolean) => void
}


export const getGlobalJavascriptState = async () => {
const {incognito} = await chrome.windows.getCurrent();
const data = {
'primaryUrl': 'http://*',
'incognito': incognito || false
};

const rule = await chrome.contentSettings.javascript.get(data);
return rule;
}


export const handleToggleGlobal = async (tab: chrome.tabs.Tab) => {
const {incognito} = await chrome.windows.getCurrent();
const {setting} = await getGlobalJavascriptState()

await chrome.contentSettings.javascript.set({
'primaryPattern': '<all_urls>',
'setting': (setting === 'block') ? 'allow' : 'block',
'scope': (incognito === true) ? 'incognito_session_only' : 'regular'
})
await updateIcon(tab);

reloadTab(tab)
}
12 changes: 12 additions & 0 deletions src/entry/background/contextmenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
handleOpenShortcut,
handlePause,
handlePlayPause,
handleToggleGlobal,
} from "./actions";
import {
cl,
Expand All @@ -38,6 +39,7 @@ import { getStorageRules } from "./storage";
import { ACTION_SHORTCUT_NAME } from "./constants";

export enum ContextMenus {
TOGGLE_GLOBAL = "TOGGLE_GLOBAL",
PLAY_PAUSE = "PLAY_PAUSE",
BLOCK_SUBDOMAIN = "BLOCK_SUBDOMAIN",
BLOCK_DOMAIN = "BLOCK_DOMAIN",
Expand Down Expand Up @@ -79,6 +81,7 @@ const SETTINGS_CONTEXT: [
] = DEFAULT_CONTEXT;

const titles = {
[ContextMenus.TOGGLE_GLOBAL]: "Toggle global",
[ContextMenus.PLAY_PAUSE]: "Pause JavaScript",
[ContextMenus.BLOCK]: "Block",
[ContextMenus.BLOCK_SUBDOMAIN]: "Block subdomain",
Expand Down Expand Up @@ -157,6 +160,12 @@ export const createContextMenus = () => {
// REMOVED BECAUSE NEEDS DEBUGGER PERMISSION AND USERS AREN'T OKAY WITH THIS
//addContextMenu({ id: ContextMenus.PLAY_PAUSE });


// For Next 2.2.0 version
// addContextMenu({
// id: ContextMenus.TOGGLE_GLOBAL
// })

// ALLOW
// addContextMenu({
// id: ContextMenus.ALLOW,
Expand Down Expand Up @@ -485,6 +494,9 @@ export const handleContextMenu = (
tab: chrome.tabs.Tab
) => {
switch (info.menuItemId) {
case ContextMenus.TOGGLE_GLOBAL:
handleToggleGlobal(tab);
break;
case ContextMenus.PLAY_PAUSE:
handlePlayPause(tab);
break;
Expand Down

0 comments on commit 4adc680

Please sign in to comment.