-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.13: enable/disable extension by clicking on extension button
- Loading branch information
Showing
6 changed files
with
187 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Update extension icon and also inform opened Discord tabs about active status change | ||
function updateDiscordTabs(result) { | ||
chrome.tabs.query({ url: "*://*.discord.com/*" }, function (tabs) { | ||
tabs.forEach(function (tab) { | ||
if (result.active) { | ||
chrome.pageAction.setIcon({ tabId: tab.id, path: "icons/icon128-active.png" }); | ||
} else { | ||
chrome.pageAction.setIcon({ tabId: tab.id, path: "icons/icon128-inactive.png" }); | ||
} | ||
chrome.tabs.sendMessage(tab.id, { active: result.active }); | ||
}); | ||
}); | ||
} | ||
|
||
// Enable/disable extension when extension button is clicked | ||
chrome.pageAction.onClicked.addListener(function (tab) { | ||
chrome.storage.local.get({ "active": true }, function (result) { | ||
// toggle active status | ||
result.active = !result.active; | ||
chrome.storage.local.set({ active: result.active }); | ||
updateDiscordTabs(result); | ||
}); | ||
}); | ||
|
||
// Initialize extension status on client when requested | ||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { | ||
if (request.action == "initialize") { | ||
chrome.storage.local.get({ "active": true }, function (result) { | ||
updateDiscordTabs(result); | ||
}); | ||
return true; | ||
} | ||
}); | ||
|
||
// Initialize extension on install | ||
chrome.runtime.onInstalled.addListener(function (details) { | ||
if (details.reason == "install") { | ||
console.log("[Hide Discord Sidebar] First install"); | ||
// Set default active state and refresh Discord pages on first install | ||
chrome.storage.local.set({ active: true }); | ||
chrome.tabs.query({ url: "*://*.discord.com/*" }, function (tabs) { | ||
tabs.forEach(function (tab) { | ||
chrome.tabs.reload(tab.id); | ||
}); | ||
}); | ||
} else if (details.reason == "update") { | ||
const thisVersion = chrome.runtime.getManifest().version; | ||
console.log("[Hide Discord Sidebar] Updated from " + details.previousVersion + " to " + thisVersion + "!"); | ||
} | ||
}); | ||
|
||
// Enable PageAction only on discord.com pages (causes extension icon have "disabled" look on other pages) | ||
// The removeRules operation is performed because the rule will be added repeatedly every time the extension is refreshed. | ||
chrome.declarativeContent.onPageChanged.removeRules(undefined, data => { | ||
chrome.declarativeContent.onPageChanged.addRules([{ | ||
conditions: [ | ||
new chrome.declarativeContent.PageStateMatcher({ | ||
pageUrl: { hostEquals: 'discord.com', schemes: ['https'] }, | ||
css: [".sidebar-2K8pFh"] | ||
}), | ||
], | ||
actions: [ | ||
new chrome.declarativeContent.ShowPageAction() | ||
], | ||
}], data => { | ||
// addRules callback | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
{ | ||
"name": "Hide Discord Sidebar", | ||
"short_name": "Hide Dis Bar", | ||
"version": "2.12", | ||
"version": "2.13", | ||
"description": "Installs an unfolding sidebar for Discord channels and a button that hides/shows the Discord server list.", | ||
"manifest_version": 2, | ||
"permissions": ["*://*.discord.com/*"], | ||
"permissions": ["*://*.discord.com/*", "storage", "declarativeContent"], | ||
"background": { | ||
"scripts": ["button-click-listener.js"], | ||
"persistent": false | ||
}, | ||
"content_scripts": [{ | ||
"matches": ["*://*.discord.com/*"], | ||
"css": ["hide-discord-sidebar.css"], | ||
"js": ["hide-discord-sidebar.js"], | ||
"run_at": "document_end" | ||
}], | ||
"icons": { | ||
"128": "icon128.png" | ||
"128": "icons/icon128-active.png" | ||
}, | ||
"browser_action": { | ||
"default_icon": "icon128.png" | ||
"page_action": { | ||
"default_icon": "icons/icon128-inactive.png" | ||
} | ||
} |