Skip to content

Commit

Permalink
fix #6 set icon, even if window is already initialized & get icon via…
Browse files Browse the repository at this point in the history
… search.currentEngine

also changed url(...) to url("...") because of problems with non-base64 data:image strings
  • Loading branch information
Istador committed Sep 18, 2018
1 parent 5b4f4b9 commit 40144f9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict"

const { Cc, Ci, document } = require('chrome')
const { Cc, Ci } = require('chrome')
const pref = require('./prefs')('extensions.blackpinguin.oldsearchfixed')

const windows = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator)
Expand Down Expand Up @@ -30,6 +30,7 @@ const [ inject, uninject ] = (() => {
return [ inject, uninject ]
})()


// calls the callback for each browser window
const forEachWindow = (callback) => {
var ws = windows.getEnumerator('navigator:browser')
Expand All @@ -40,18 +41,18 @@ const forEachWindow = (callback) => {

// sets the icon or resets it back to the default for search bars in all windows
const setIcon = (val = true) => {
if (val && pref('searchbar.icon', true)) {
forEachWindow((w) => {
let icon = w.BrowserSearch.searchBar.boxObject.lastChild.children[0].children[0].children[0]
icon.style.cssText = 'list-style: none; background-image: url(' + w.BrowserSearch.searchBar.getAttribute('src') + '); background-size: 16px; background-position: center center; background-repeat: no-repeat;'
})
}
else {
forEachWindow((w) => {
let icon = w.BrowserSearch.searchBar.boxObject.lastChild.children[0].children[0].children[0]
icon.style.cssText = ''
})
}
let img = search.currentEngine.iconURI.asciiSpec

let css = (
img && val && pref('searchbar.icon', true)
? 'list-style: none; background-image: url("' + img + '"); background-size: 16px; background-position: center center; background-repeat: no-repeat;'
: ''
)

forEachWindow((w) => {
let icon = w.BrowserSearch.searchBar.boxObject.lastChild.children[0].children[0].children[0]
icon.style.cssText = css
})
}


Expand All @@ -73,6 +74,8 @@ const changeEngine = (type, engine) => {
const init = (() => {
var initialized = []
return (w) => {
if (w.BrowserSearch) { setIcon() }

if (initialized.indexOf(w) !== -1) return

if (w.BrowserSearch) {
Expand All @@ -83,7 +86,6 @@ const init = (() => {
return false
}
})
setIcon()
}

if (w.gURLBar) {
Expand Down

0 comments on commit 40144f9

Please sign in to comment.