Tag Archives: JavaScript

npm install webdriver is not working properly: 3 solutions

So, you thought about using locally installed Microsoft Edge (chromium) or Google Chrome as automaton for your nodeJS project? Bad luck, the webdriver versions available on npm for Windows do not match the browser’s MAJOR version… That’s a FAIL! Here is how to circumvent this problem.

Continue reading npm install webdriver is not working properly: 3 solutions

Automatic Header Anchors for WordPress Without Plugin

Header Anchors for WordPress with only 3 lines of JS and No plugin?? Yes It’s so easy to set up… Thank you IT Cooking! The JS requires your headers to have an ID, and what better then a Table Of Content plugin to have them for free!

Header Anchors for WordPress Step by Step Process

Requisites

Required: A Snippet loader: we recommend Simple Custom CSS & JS

Simple Custom CSS and JS banner

Optional: A table of content plugin: we recommend TOP Table Of Contents

banner top toc

The JS snippet provided also adds ids to your headers…

Add this JS Snippet to Attach an Anchor to Headers

window.addEventListener("load", function(){
  // Loop through all your headers inside article section only
  // Headers shall be there thanks to TOC plugin, if not we just add them
  // AddOnly h2 and h3, add the headers you want
  $("article").find("h2, h3").each(function() {
    if (!this.id) {
      let id = this.textContent.replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
      this.setAttribute('id', id);
    }
    $(this).append('<a class="anchor" href="#'+this.id+'"></a>');  // anchors after
    //$(this).prepend('<a class="anchor" href="#'+this.id+'"></a>'); // anchors before
    });
});

The JS appends/prepends a link with class .anchor to every h2/h3 found on the page, that have an id or not. Will add ids if missing. It does NOT add links to headers outside the article content (read more, etc).

Add this CSS to Format the Anchors

.anchor {
  visibility: hidden;
  text-decoration: none !important;
}
/* add more levels if you need */
h3:hover > .anchor, 
h2:hover > .anchor {
  visibility: visible;
}
.anchor::before { 
  content: "🔗";
}

Anchor is visible on hover, right side, and is an emoji. You can replace the emoji by an <i> from fontawesome if you like.

Result:

css js snippets to add anchor to headers

 

Meltdown and Spectre: Why the Commotion?

 

Another commotion is spreading across the Internet about a potential threat: Meltdown and Spectre critical vulnerabilities found in Intel and other ARM CPUs will be exploited and hackers will steal your money, erase your data and mow your cat, blah blah blah.

If hackers knew or could have exploited it, you would have noticed. Catching fire now is too late. “Spectre” vulnerability is 15 years old. Now, please remember the Year 2000 bug hoax and follow the money ????

I’d like to be the bearer of good news, because you are all wrong about this threat. NO NEED TO PANIC and here is why:

Continue reading Meltdown and Spectre: Why the Commotion?

Copy Text Button in WordPress – Click… It’s Copied!

Copy Text Copy Text Copy Text

Adding the ability to Copy Text Code Blocks Without Flash, with a click from a Copy Text Button inside a Syntax highlighted Code Block, that’s real magic. Bonus: the copied code includes Rich Text Format (RTF syntax). This solution relies on Clibboard.JS, and is the easiest one to add to your site. I could make it work under two hours, so I hope this tutorial will help you make it in less!

This text will be copied onto the clipboard 
when you click the button below. 
Try it!

Continue reading Copy Text Button in WordPress – Click… It’s Copied!

Syntax Highlight Code with EnlighterJS for WordPress

Highlight Code with EnlighterJS for WordPress is pretty easy and the results are awesome. There are plenty of highlighter frameworks around for WordPress, such as Crayon.js and Highlighter.js, but I prefer this one.

It’s faster and lighter than Crayon while offering most of its options. Also I like the WordPress plugin integration better.

EnlighterJS For WordPress

This is even easier! Just install EnlighterJS plugin.

hen make sure to activate it and select the CDN for the MooTools framework (if you use CDNjs):

Redources & CDN settings

 

Code added with the add code button will look like this in your posts:

<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;!--load EnlighterJS:--&gt;

...some js code..

</pre>

EnlighterJS in 2024 now includes a Copy code button. The ‘Copy to Clipboard‘ button I added back in 2017 was a hack done with Clipboard.js, you can check how to add the copy code button for WordPress here.

EnlighterJS For Standalone Sites

First you need to download the package. EnlighterJS css and JS are note currently available on cdnjs for some reason.

Then all you have to do is add this code in the footer:

<!--load EnlighterJS:-->
<link rel='stylesheet' href='css/EnlighterJS.min.css' type='text/css' />
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/mootools/1.6.0/mootools-core.min.js'></script>
<script type='text/javascript' src='js/EnlighterJS.min.js?ver=3.5'></script>

<pre data-enlighter-language="js">
Element.implement({
...some js code..
});
</pre>

Pretty straightforward isn’t it?

EDIT 2024: EnlighterJS is still the best Syntax Highlighter plugin for WordPress in 2024!