aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-08-21 21:32:42 +0530
committerAkshay Nair <phenax5@gmail.com>2024-08-21 21:32:42 +0530
commitdb667b17820599d850d22d6d9345fb507d399a0d (patch)
tree589aee0edc29b041b11be57101831a683091adbc
parent397f3cdf4862c2912212a00cd799a920b654aa8a (diff)
downloadnixos-config-db667b17820599d850d22d6d9345fb507d399a0d.tar.gz
nixos-config-db667b17820599d850d22d6d9345fb507d399a0d.zip
Add loading indicator to firefox urlbar
Diffstat (limited to '')
-rw-r--r--modules/firefox.home/chrome/loadingIndicator.uc.js109
-rw-r--r--modules/firefox.home/chrome/userChrome.css37
2 files changed, 142 insertions, 4 deletions
diff --git a/modules/firefox.home/chrome/loadingIndicator.uc.js b/modules/firefox.home/chrome/loadingIndicator.uc.js
new file mode 100644
index 0000000..61ba50b
--- /dev/null
+++ b/modules/firefox.home/chrome/loadingIndicator.uc.js
@@ -0,0 +1,109 @@
+// ==UserScript==
+// @name Loading indicator
+// @version 1.0
+// @description Loading indicator for the url bar
+// @startup UC.loadingIndicator.init(win)
+// @shutdown UC.loadingIndicator.destroy()
+// ==/UserScript==
+
+(() => {
+ const ENABLED = true;
+
+ class TabProgressListener {
+ static instances = [];
+
+ static createListener(tab, onStateChange) {
+ const oldListener = TabProgressListener.instances.find(l => l.tab === tab)
+ if (oldListener) return oldListener;
+ const listener = new TabProgressListener(tab, onStateChange);
+ TabProgressListener.instances.push(listener);
+ listener.attach();
+ return listener;
+ }
+
+ static cleanup() {
+ TabProgressListener.instances.forEach(l => l.cleanup())
+ }
+
+ loadedPercentage = 0;
+ constructor(tab, onStateChange) {
+ this.tab = tab;
+ this._stateChange = onStateChange;
+ }
+
+ attach() {
+ const browser = this.tab.linkedBrowser;
+ browser.webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_ALL)
+ }
+
+ cleanup() {
+ try {
+ const index = TabProgressListener.instances.indexOf(this);
+ if (index !== -1)
+ TabProgressListener.instances.splice(index, 1);
+ } finally {
+ this.tab.linkedBrowser.webProgress.removeProgressListener(this);
+ }
+ }
+
+ // Start query listener methods
+
+ QueryInterface = ChromeUtils.generateQI(['nsIWebProgressListener', 'nsISupportsWeakReference'])
+
+ onStateChange(_webProgress, _request, stateFlags, _status) {
+ if (stateFlags & Ci.nsIWebProgressListener.STATE_START) {
+ this._stateChange?.('loading');
+ } else if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
+ this._stateChange?.('loaded');
+ }
+ }
+ }
+
+ const module = {
+ onProgressStateUpdate: (win, state) => {
+ /** @type {HTMLElement} */
+ const urlBar = win.gURLBar.textbox;
+ console.log(state, urlBar);
+ if (!urlBar) return;
+
+ // urlBar.style.setProperty('--ff-urlbar-progress', perc);
+ urlBar.dataset.pageProgress = state;
+ },
+
+ setupTab: (tab, win) => {
+ const listener = TabProgressListener.createListener(tab, (state) => module.onProgressStateUpdate(win, state));
+
+ tab.addEventListener('TabClose', () => listener.cleanup());
+ },
+
+ setupWindow: win => {
+ win.gBrowser.tabs.forEach(tab => module.setupTab(tab, win));
+ win.gBrowser.tabContainer.addEventListener('TabOpen', event => {
+ module.setupTab(event.target, win);
+ });
+ win.gBrowser.tabContainer.addEventListener('TabSelect', _event => {
+ const isLoading = gBrowser.selectedTab.linkedBrowser.webProgress.isLoadingDocument
+ module.onProgressStateUpdate(win, isLoading ? 'loading' : 'loaded');
+ });
+ },
+
+ init(win) {
+ if (!ENABLED) return;
+
+ const handle = () => {
+ Services.obs.removeObserver(handle, 'browser-window-before-show');
+ module.setupWindow(win);
+ }
+
+ if (win.__SSi) handle();
+ else Services.obs.addObserver(handle, 'browser-window-before-show');
+ },
+
+ destroy() {
+ TabProgressListener.cleanup();
+ },
+ };
+
+ UC.loadingIndicator = module;
+})()
+
diff --git a/modules/firefox.home/chrome/userChrome.css b/modules/firefox.home/chrome/userChrome.css
index 99dc670..e50a3db 100644
--- a/modules/firefox.home/chrome/userChrome.css
+++ b/modules/firefox.home/chrome/userChrome.css
@@ -157,7 +157,36 @@ toolbarbutton#alltabs-button {
#sidebar-splitter {
display: none !important;
}
-/* #appcontent { */
-/* border-radius: 4px !important; */
-/* overflow: hidden !important; */
-/* } */
+
+
+
+/* URL bar progress indicator */
+#urlbar[data-page-progress="loaded"]::before {
+ display: none !important;
+}
+
+@keyframes ucLoadingSnimation {
+ 0% { background-position: 130% 50%; }
+ 100% { background-position: -70% 50%; }
+}
+
+#urlbar[data-page-progress]::before {
+ display: block;
+ content: " ";
+ pointer-events: none;
+ width: 100%;
+ height: 100%;
+ position: absolute;
+ bottom: 0;
+ left: 0;
+ z-index: 1;
+ background: linear-gradient(
+ 140deg,
+ rgba(255, 255, 255, 0) 35%,
+ rgba(255, 255, 255, .25) 50%,
+ rgba(255, 255, 255, 0) 65%
+ ) rgba(255, 255, 255, 0.05);
+ background-size: 200% 200%;
+ animation: ucLoadingSnimation 2.2s ease-in-out infinite;
+ border-bottom: 2px solid var(--ff-accent-color);
+}