Last active
August 7, 2024 09:32
-
-
Save UnluckyNinja/5a3cc22d9708327bcdfe8bf14a8edc08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for https://craftinginterpreters.com to re-align aside elements after using a translation service | |
// copy & paste whole script into a tool like https://chriszarate.github.io/bookmarkleter/ | |
// to make it a convenient bookmarklet | |
const AVOID_CONFLICT_NAME = '__aside_listeners' | |
const handles = window[AVOID_CONFLICT_NAME]|| [] | |
handles.forEach(it=>it()) | |
$('aside').each(function(){ | |
const cur = $(this) | |
let prev = cur.prev(); | |
while(prev.css('display') === 'none'){ | |
prev = prev.prev() | |
} | |
if (prev[0].nodeName.toLowerCase() === 'aside'){ | |
cur.css('top', prev.position().top + prev.height() + 10) | |
} else { | |
cur.css('top', prev.position().top) | |
} | |
function mouseIn(){ | |
cur.css('background', '#FFFFFFF8') | |
cur.css('z-index', '100') | |
} | |
function mouseOut(){ | |
cur.css('background', 'transparent') | |
cur.css('z-index', '') | |
} | |
prev.on('mouseenter', mouseIn).on('mouseleave', mouseOut) | |
handles.push(()=>{ | |
prev.off('mouseenter', mouseIn).off('mouseleave', mouseOut) | |
}) | |
}); | |
window[AVOID_CONFLICT_NAME]= handles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment