Del/Ins corrector - Composer Extension (UserScript)
-
//Monarch $(document).ready(function(){window.PagedownCustom.appendButtons.push({id:"wmd-del-button",description:"del/ins correction",execute:function(a){a.before+="<del>"+a.selection+"</del><ins>";a.selection=" ";a.after="</ins>"+a.after}});$(document.body).append('<style> #wmd-del-button::before {content: "\\f12d";}</style>')});
Thanks @Zecc for the original idea, and @Onyx for the
ideainspiration.http://what.thedailywtf.com/uploads/default/20521/143513050ab042af.mp4
-
Added.
-
-
-
testwillies
-
-
It's easy when you can just inject into source!
Some of the things just don't work from Userscripts. Like injecting styles into
<head>
for example. No idea why not, but they get injected but not applied.Also, I was about to mention @Zecc but I got 'd
-
-
-
-
So when it first renders the quote it shows @aliceif's avatar then it disappears presumably thanks to the highlighting.
-
@Monarch said:
Thanks
@.Onyx@.Zecc forinspirationidea.
You're welcome. And thank you for making this a reality.
-
No idea why not, but they get injected but not applied.
There is a minor gotcha with that particular style, when added via jQuery with regard to escaping.
--------------------------------------------------------------------| V $(document.body).append('<style> #wmd-del-button::before {content: "\\f12d";}</style>')
Other then that there should be no problem applying style from anywhere( userscript / console). once that style tag is in the document it will get evaluated.
-
There is a minor gotcha with that particular style, when added via jQuery
Well of-fucking-course.
Another one for the future though:
window.PagedownCustom.appendButtons
Where do I find info on this stuff? Do I have to troll the source? I found a reference to this in a JS file (next to... Morph object, I think?) but I apparently misunderstood what to do with it, I tried to add button using that but no dice.
-
window.PagedownCustom.appendButtons
Where do I find info on this stuff? Do I have to troll the source?
Haven't you read the Discodocs.
Tip 1: Use github to search the code, don't look in the DevTools.
A lesson you already learned, debugging the code is not a fun process specially due to some weaknesses in Devtools itself and not limited to the added complexity of the framework.I was lucky to stumble on the usage of the api in the code, by analysing the source in tracing back potential access points to inject the hack, and it worked much easier then I anticipated.
if I had to invent the wheel, injecting the button would have been a much uglier solution. it would have involved detection of every build of the composer interface which can occur every time the composer is opened. and bind my own handlers, detect the textarea selection and to the replacements.
Let say we were just lucky that the discodev needed that functionality otherwise it would have been a big pain.
To answer your question, yes it is pretty much trolling the source. obviously there is no public api and no docs.
-
A lesson you already learned, debugging the code is not a fun process specially due to some weaknesses in Devtools itself and not limited to the added complexity of the framework.
Yeah, that code you pasted never got hit by the debugger, even when tracing all node updates. Annoying.
-
I just did this manually in another topic because I hadn't seen this topic, yet, and didn't notice the new button.
-
This shit is so easy now that @Monarch found the reference, I'd be embarrassed to open a topic for this:
$(document).ready(function() { window.PagedownCustom.appendButtons.push({ id:"wmd-abbr-button", description:"abbreviation", execute:function(a){ var originalText = a.selection; a.before += '<abbr title="'; a.selection=" "; a.after='">' + originalText + '</abbr>' + a.after } }); $(document.body).append('<style> #wmd-abbr-button::before {content: "\\f071";}</style>') });
Have an
<abbr>
button. Have funAnd no, I really had no idea what to use as the icon. Fix as needed: cheatsheet.
And I really don't need that extra variable, do I? Coding at 1AM everyone!
I'll leave it, so my shame can live on in infamy.
-
And I really don't need that extra variable, do I?
you probably don'ta.before += '<abbr title="'; a.after= '">' + a.selection + '</abbr>' + a.after; a.selection=" "; //moved down
-
Oh, I'm sure I don't. I was doing this half asleep, posted the idiot version, realized that it's stupid and then just left it be anyway, as a reminder to myself of how much stupid I'm capable of
-
I just used this for the first time.
Thanks again.
-
Thanks for the addition. Should this button appear on mobile? My screen's pretty small so it may have dropped off, but I'm not getting it on the tablet.
-
Don't get any buttons on mobile IIRC. Mobile users get the peasant experience.
-
You mean this ISN'T the peasant experience??
Maybe I'm not getting the mobile site on the tablet. I won't lie, I don't care a huge amount. I'll have a closer look at some point.
-
My tablet gets desktop, it's very possible
-
Have an <abbr> button. Have fun
you probably don't
Have you guys noticed it yet?
BTW, I forgot to look at this and just used the original del/ins code to come up with the equivalent.
-
Oh! I have two now! But they both picked up my chosen icon, I guess you picked the same name for the class
-
Yes, I just did the laziest thing I could.
-
Which one did you use? I looked through all the fa-stuff and
:fa_text_width:
seemed close enough to text with the dotted underline.
-
Aaand one script less to run.
I have an interesting one coming up, but I doubt that one's going to be included by default. Have to finish it first, too, no time the last few days...
Which one did you use?
, due to... yeah, not really a good choice around for
<abbr>
so I went with whatever seemed kinda sane.
-
Ah, that one's pretty good. I think I'll use it. It actually fits semantically.
-
BTW, I forgot to look at this and just used the original del/ins code to come up with the equivalent.
I get a black i-in-circle, not that icon.
Edit: never mind.
-
What about ?
-
My first reaction is: why is belgium spelled with only three letters?
-
What about ?
As @Boomzilla noted
@boomzilla said:My first reaction is: why is belgium spelled with only three letters?
That should be reserved for the
[Insert belgium at current cursor position]
button
-
That should be reserved for the [Insert belgium at current cursor position] button
Belgium !
-
test
testtest test
-
@sloosecannon said:
That should be reserved for the [Insert belgium at current cursor position] button
■TFY
FTFY
-
In case this is useful for anyone else.
Insert "Filed under:" tags.$(document).ready(function() { window.PagedownCustom.appendButtons.push({ id:"wmd-tag-button", description:"add filed under tag", execute:function(a){ a.before += '\n<br><hr>\n\nFiled under: ['; a.selection=" "; a.after=']()' } }); $(document.body).append('<style> #wmd-tag-button::before {content: "\\f02b";}</style>') });
Filed under: Might change the icon
-
Wouldn't the
[]()
link syntax be easier?
-
given that this works, i'm going woth yes
-
-
Easier than clicking a single button and copying the output?
It's now I've done it anyway.
-
Yeah just saw the cloud first. Amended.
-
Amended as it looks tidier.
-
Filed Under +1!, We need a new tag cloud to attack, FUCKING HELL WHY DOES IT INSERT TWO FILED UNDERS WHEN I ONLY CLICKED ONE
-
given that this works, i'm going woth yes
I spend an unflattering amount of time hovering that link trying to figure out its URL. I finally gave up and checked the raw.
-
String.fromCharCode(13)
don't you mean
'\n'
there? (it's shorter and more recognizeable)
-
Amended, whatever.
-
I Jeffed 7 posts to an existing topic: Reasons loopback0 shouldn't listen to SO about JavaScript (or anything probably)