diff --git a/show-alternate/index.js b/show-alternate/index.js index 1b1d35a361c38d7e572ab29ab7ed2db9d1dbe691..722d7ccb330b9fbb185a5d6a5c248bc41e7f926d 100644 --- a/show-alternate/index.js +++ b/show-alternate/index.js @@ -1,10 +1,10 @@ // ==UserScript== // @name Show alternate links // @namespace http://hugo.hornquist.se -// @version 0.1.1 +// @version 0.2.0 // @description Show alternate links // @author hugo@lysator.liu.se -// @match *://* +// @match *://*/* // @updateURL https://git.lysator.liu.se/hugo/web-monkey-scripts/raw/master/show-alternate/index.js // @downloadURL https://git.lysator.liu.se/hugo/web-monkey-scripts/raw/master/show-alternate/index.js // @source https://git.lysator.liu.se/hugo/web-monkey-scripts/-/tree/master/show-alternate @@ -14,7 +14,7 @@ (function () { 'use strict'; - let id = `id-${Math.random()}` + let id = `id-${Math.floor(Math.random() * 1e6)}` let outer = document.createElement('div'); let inner = document.createElement('div'); @@ -23,7 +23,9 @@ outer.appendChild(inner); inner.appendChild(ul); + let link_count = 0 for (let link of document.querySelectorAll('link[rel=alternate]')) { + link_count++ let li = document.createElement('li'); let a = document.createElement('a') a.href = link.href @@ -32,21 +34,39 @@ ul.appendChild(li) } - GM_addStyle(` - #${id} { - margin: 0 !important; - position: absolute; - top: 0; - right: 0; - background: red; + if (link_count > 0) { + document.body.appendChild(outer) } - #${id} > div { - display: none; - } + GM_addStyle(` +#${id} { + margin: 0 !important; + position: absolute; + top: 0; + right: 0; + display: block; + width: 2em; + min-height: 2em; + background: red; + color: white; + font-weight: bold; + padding: 1ex; +} - #${id}:hover > div { - display: block; - } - `) +#${id}:hover { + width: unset; +} + +#${id} ul { + padding: revert; +} + +#${id} > div { + display: none; +} + +#${id}:hover > div { + display: block; +} +`) })();