When working with jQuery on webpages, I regularly use the Devtools context menu option ‘Copy JS path’, this produces something like:
document.querySelector('element1 > element2')
then I always need to replace 'document.querySelector'
with a '$'
for jQuery to work… so tedious!
I wrote a small Autohotkey utility script which detects 'document.querySelector'
when in the clipboard and automatically replaces it with a '$'
– it’s very simple and effective.
install Authotkey, save as ‘clippie.ahk’ (for example):
#Persistent
OnClipboardChange("ClipChanged")
return
ClipChanged(Type) {
StringReplace, clipboard, clipboard, document.querySelector,
$, All
}
(minor note: if you ever need to copy/paste ‘document.querySelector
‘, just copy/paste ‘document.querySelecto
‘ and then manually add ‘r
‘ at the end)
Or, if you’re brave, I compiled the script into an .exe you can download: clippie – Copy jQuery path
Why not just use the native document.querySelector? jQuery isn’t giving you any benefit over querySelector.
to start using jQuery’s features you first need $, then you can continue as usual by adding jQuery syntax at the end of the line… unless being anti-jQuery and mean it’s unneeded
Members
Online