diff --git a/src/EnhancedXcodeTags.user.js b/src/EnhancedXcodeTags.user.js index 80e31c9..d106591 100644 --- a/src/EnhancedXcodeTags.user.js +++ b/src/EnhancedXcodeTags.user.js @@ -80,23 +80,28 @@ if (GM_getValue("dark_mode") === undefined) { document.addEventListener('DOMContentLoaded', function() { const blocks = document.querySelectorAll('pre.line-numbers'); for (const block of blocks) { + let wrapper = document.createElement("div"); + wrapper.setAttribute("class", "xcode_container"); + let div = document.createElement("div"); div.setAttribute("class", "input-container"); div.setAttribute("title", "Toggle Color Theme"); let input = document.createElement("input"); input.setAttribute("id", "darkTheme"); - input.setAttribute("class", "setting"); + input.setAttribute("class", "xcode_switch"); input.setAttribute("type", "checkbox"); input.addEventListener('change', darkSwitch, false); let label = document.createElement("label"); - label.setAttribute("class", "setting"); + label.setAttribute("class", "xcode_switch"); label.setAttribute("for", "darkTheme"); + block.parentNode.insertBefore(wrapper, block); div.append(input); div.append(label); - block.prepend(div); + wrapper.append(block); + wrapper.append(div); } if (JSON.parse(GM_getValue("dark_mode", "{}")) === true) { @@ -124,7 +129,7 @@ document.addEventListener('DOMContentLoaded', function() { } function toggleSwitch(value) { - const inputs = document.querySelectorAll('input.setting'); + const inputs = document.querySelectorAll('input.xcode_switch'); for (const input of inputs) { input.checked = value; } diff --git a/src/css/xcode-switch.css b/src/css/xcode-switch.css index 464d5d6..a1cd915 100644 --- a/src/css/xcode-switch.css +++ b/src/css/xcode-switch.css @@ -1,28 +1,43 @@ -.input-container { +div.xcode_container { position: relative; - float: right; } -.setting { +div.xcode_container > .input-container { + position: absolute; + top: 1.3em; + right: .6em; + transition: opacity 0.3s ease-in-out; + opacity: 0; +} + +div.xcode_container:hover > .input-container { + opacity: 1; +} + +div.xcode_container:focus-within > .input-container { + opacity: 1; +} + +div.xcode_container > .input-container > .xcode_switch { cursor: pointer; display: block; position: relative; height: 14px; } -.setting::selection { +div.xcode_container > .input-container > .xcode_switch::selection { background: transparent; } -.input-container input[type=checkbox] + label:before { +div.xcode_container > .input-container input[type=checkbox] + label:before { box-shadow: none; } -.input-container input[type=checkbox]:checked + label:before { - background: #7192a8; /*#27a6e5;*/ +div.xcode_container > .input-container input[type=checkbox]:checked + label:before { + background: #7192a8; } -.input-container input[type=checkbox] + label:before { - background: #e9e9e9; /*#808080;*/ +div.xcode_container > .input-container input[type=checkbox] + label:before { + background: #e9e9e9; border-radius: 100px; box-shadow: 0 0 2px 0 #333 inset; box-sizing: border-box; @@ -39,11 +54,11 @@ transform: translateY(-50%); } -.input-container input[type=checkbox]:not(:checked) + label:after { +div.xcode_container > .input-container input[type=checkbox]:not(:checked) + label:after { left: 8px; } -.input-container input[type=checkbox] + label:after { +div.xcode_container > .input-container input[type=checkbox] + label:after { background: #fff; border-radius: 90px; box-shadow: 0 0 3px 0 #333; @@ -62,11 +77,11 @@ margin-right: 6px; } -.input-container input[type=checkbox] + label { +div.xcode_container > .input-container input[type=checkbox] + label { padding-left: 46px; } -.input-container input[type=checkbox] { +div.xcode_container > .input-container input[type=checkbox] { display: none; height: 0; visibility: hidden;