diff options
-rw-r--r-- | js/vapi-background.js | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js index 55ce363..cca47c6 100644 --- a/js/vapi-background.js +++ b/js/vapi-background.js @@ -2476,11 +2476,27 @@ vAPI.toolbarButton = { // Found our button on this toolbar - but where on it? var before = null; for ( var i = index + 1; i < currentset.length; i++ ) { - if (currentset[i] === 'spacer') { - // The [id=...] notation doesn't work on - // 'toolbarspacer' elements. - // https://gitlab.com/vannilla/ematrix/issues/5 - before = toolbar.querySelector('toolbarspacer'); + // The [id=...] notation doesn't work on + // space elements as they get a random ID each session + // (or something like that) + // https://gitlab.com/vannilla/ematrix/issues/5 + // https://gitlab.com/vannilla/ematrix/issues/6 + + // Based on JustOff's snippet from the Pale Moon forum. + // It was reorganized because I find it more readable like this, + // but he did most of the work. + let space = /^(spring|spacer|separator)$/.exec(currentset[i]); + if (space !== null) { + let elems = toolbar.querySelectorAll('toolbar'+space[1]); + + let count = currentset.slice(i-currentset.length) + .filter(function (x) {return x == space[1];}) + .length; + + before = + toolbar.querySelector('[id="' + + elems[elems.length-count].id + + '"]'); } else { before = toolbar.querySelector('[id="'+currentset[i]+'"]'); } |