The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘Web Development’ Category

In the WordPress classic editor, avoid the SyntaxHighlighter Code Block

Posted by jpluimers on 2023/10/25

When you use the WordPress classic editor (which for me still works far better than the Gutenberg one), avoid at all cost the use of the [Wayback/Archive] SyntaxHighlighter Code Block – Page 2 – WordPress.com Support.

Each time you switch between from Text View back to Visual, some characters are html-encoded, like:

  • & becomes &
  • > becomes >

Switching twice makes & into &&gt.

Switching three times makes & into &&&gt.

I already explained why to avoid the Gutenberg editor in Bookmarklet to force WordPress classic-editor.

Via:

–jeroen

Posted in Classic editor, Development, Gutenberg editor, SocialMedia, Software Development, Web Development, WordPress, WordPress | Leave a Comment »

Chrome (likely also Firefox/Edge/Safari): no non-global way to workaround Bookmarklets failing on GitHub raw code with “Blocked script execution…”

Posted by jpluimers on 2023/10/18

Last year, I answered [Wayback/Archive] javascript – Bookmarklet to append a string to a URL – Stack Overflow (asked by [Wayback/Archive] Karlo Guidoni Martins, thanks!).

It is about not being able to run bookmarklets on pages hosted by for instance:

  • gist.githubusercontent.com
  • raw.githubusercontent.com

GitHub is an exception, as RAW files from these services do work fine:

At first sight, when running a Bookmarklet on those RAW GitHub served pages, you do not see an error: it just looks like the Bookmarklet does not work at all. The last part is right, but in the Chrome console you can actually see the error.

That error lead me to my answer:

Read the rest of this entry »

Posted in Bookmarklet, Chrome, Development, Firefox, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers, Web Development | Leave a Comment »

Javascript – Copy string to clipboard as text/html – Stack Overflow

Posted by jpluimers on 2023/09/27

For my link archive is the below answer that should help me a lot with unfinished bits from Some JavaScript bookmarklets for WordPress published pages centered around navigation and IDs.

Goal of that post was to have some grounding and eventually find a means to build an HTML page in a new tab using a bookmarklet that I then later could post to my blog.

Assembling to HTML and putting it on the clipboard might be a lot easier and better fitting in my workflow.

So, via [Wayback/Archivejavascript copy html to clipboard – Google Search, for my link archive: [Wayback/Archive] Javascript – Copy string to clipboard as text/html – Stack Overflow (thanks [Wayback/Archive] Loilo for answering and [Wayback/Archive] kofifus for asking):

Below is a function that will do exactly that. I tested it with your required browsers, it works in all of them. However, IE 11 will ask for confirmation on that action.

Explanation how this works can be found below, you may interactively test the function out in this jsFiddle.

Read the rest of this entry »

Posted in Chrome, Development, Firefox, HTML, HTML5, Internet Explorer, JavaScript/ECMAScript, JSFiddle, Power User, Scripting, Software Development, Web Browsers, Web Development | Leave a Comment »

XPath based bookmarklets for Archive.is: more JavaScript fiddling!

Posted by jpluimers on 2023/09/20

As I promised a few months back in Bookmarklets for Archive.is and the WayBack Machine to go to the original page, moar JavaScript fiddling, this time with XPath based bookmarklets to navigate from Archive.is pages to Saved From, Redirected from, Via and Original pages.

An alternative would be using XPath as the additional fields are always structured in a table like the html below (taking complex pages like https://archive.ph/5iVVH and https://archive.ph/2015.11.14-044109/http://www.example.org/ as an example).

I got triggered to using XPath from this answer from [Wayback/Archive] gdyrrahitis at [Wayback/Archive] Javascript .querySelector find by innerTEXT – Stack Overflow (thanks [Wayback/Archive] passwd for asking):

Read the rest of this entry »

Posted in Agile, Bookmarklet, Code Quality, Code Review, Development, HTML, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers, Web Development, XML/XSD, XPath | Leave a Comment »

I recently learned about the MacOS universal Shift-Option-Command-V keyboard shortcut: paste without formatting

Posted by jpluimers on 2023/09/19

Boy, two extra modifier keys: [Wayback/Archive] How to Strip Formatting When You Copy and Paste Text: 5 Ways

To paste as plain text on a Mac, you can use the somewhat cumbersome shortcut Option+Cmd+Shift+V to paste without formatting. This is a system-wide shortcut, so unlike Windows, it should work everywhere. Technically, the shortcuts pastes and matches the formatting, but this has the same effect of removing the original formatting.

Via [Wayback/Archive] macos word microsoft office paste without formatting – Google Search.

Paste without formatting is an issue on Windows as well. The default should be “paste without formatting” instead of the current “paste with source formatting”. See for instance these tweets:

Read the rest of this entry »

Posted in Apple, Classic editor, Development, Gutenberg editor, Mac OS X / OS X / MacOS, Office, Office 2011 for Mac, Power User, Software Development, Web Development, WordPress | Leave a Comment »

Revision of some JavaScript bookmarklets for WordPress published pages centered around navigation and IDs: WordPress ditched the undocumented HighlanderComments structure

Posted by jpluimers on 2023/09/15

As promised yesterday, I updated the scripts for Some JavaScript bookmarklets for WordPress published pages centered around navigation and IDs

Code (which broke at 20230914 because of WordPress.com changes: the undocumented HighlanderComments structure got removed; I will update the gist later on and post an updated blog post)

Instead of the undocumented HighlanderComments structure, I now use two (also undocumented) link rel elements.

In addition, I found this element that will be interesting in the future: <link rel='shortlink' href='https://wp.me/pvelJ-m8g' />.

You can view the change with the below archivals of the Wayback Machine and Archive.is.

And of course I learned a few things from these MDN entries:

The 20230530 archivals (Wayback/Archive) of wiert.me/2022/02/14/philosophy-of-management have this HighlanderComments structure:

Read the rest of this entry »

Posted in Bookmarklet, Conference Topics, Conferences, Development, Event, HTML, JavaScript/ECMAScript, Power User, Scripting, SocialMedia, Software Development, Web Browsers, Web Development, WordPress | Leave a Comment »

Some notes on the WordPress Press-This bookmarklet

Posted by jpluimers on 2023/08/23

I want to improve my WordPress blogging experience especially since most of the pages I link also have two extra links of the archived pages in the Wayback Machine and Archive.is.

The WordPress Press-This bookmarklet does not always cut it. It is slow too as it does a POST request to the WordPress site which then renders a new page.

It is also highly minified, so below are some links that will hopefully allow me to research it further to see if I either could improve it for my own workflow, or need to start from scratch.

I want to figure out:

  • what the values of the v= version parameter were (I know about v=8 and v=4, there are likely more)
  • which commits were involved
  • can I get more information (like summary, first heading or first paragraph of a page too)
  • what techniques are used for opening new windows/tabs

TODO: make diffs of the various versions

–jeroen

Posted in Bookmarklet, Development, JavaScript/ECMAScript, Power User, Scripting, SocialMedia, Software Development, Web Browsers, Web Development, WordPress, WordPress | Leave a Comment »

Bookmarklet to save a page both in the WayBack machine and Archive.is (ending on the latter to solve a reCAPTCHA)

Posted by jpluimers on 2023/08/22

TL;DR:

javascript:{h=location.href;open('https://archive.is/?run=1&url='+encodeURIComponent(h));location.href='https://web.archive.org/save/'+(h)}

Read the rest of this entry »

Posted in Bookmarklet, Development, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers, Web Development | Leave a Comment »

Youtube – Extract Meta Data – Amnesty International

Posted by jpluimers on 2023/08/16

Cool that Amnesty International can do a YouTube [Wayback/Archive] Extract Meta Data (Amnesty International).

Via:

I wonder if I can write a Bookmarklet for this (it will likely require an HTTP POST request).

–jeroen

Posted in Development, HTML, JavaScript/ECMAScript, LifeHacker, Power User, Privacy, Scripting, SocialMedia, Software Development, Web Development, YouTube | Leave a Comment »

Load jQuery Only If Not Present

Posted by jpluimers on 2023/07/26

Since I will likely need this one day:

Searching for the above, I ended up in some kind of YouTube vortex or time sink. This happens a lot when learning new stuff, so lets dump a bit more of what I learned along the way.

Watch your $

For checking for the availability of version of jQuery, lots of links I found use $(). or $. constructs which depend on the context of $ being the global alias for the jQuery. When mixing libraries, this global symbol (yes, unlike many languages $ and _ are valid and heavily symbols in JavaScript) can be used by any of these libraries and if you are not absolutely sure about your context, using them is a plain risk: [Wayback/Archive] Global Variables Are Bad.

Adding to the confusion, there are both the jQuery() and jQuery, which seem to be distinctly different. To add to the confusion, there is also jquery.

Since JavaScript is weakly typed, any typos are for you (in the sense of “you, the developer”) to figure out.

Some links from the vortex are below.

Confirmation of my fear of a using global names

  • [Wayback/Archive] Why does JQuery have dollar signs everywhere? – Stack Overflow (thanks [Wayback/Archive] Sachin Kainth for asking, and [Wayback/Archive] User T.J. Crowder for answering)
    $ is just a shortcut for jQuery. The idea is that everything is done with the one global symbol (since the global namespaces is ridiculously crowded), jQuery, but you can use $ (because it’s shorter) if you like:
    // These are the same barring your using noConflict (more below)
    var divs = $("div");       // Find all divs
    var divs = jQuery("div");  // Also find all divs, because
    console.log($ === jQuery); // "true"
    
    If you don’t want to use the alias, you don’t have to. And if you want $ to not be an alias for jQuery, you can use noConflict and the library will restore $ to whatever it was before jQuery took it over. (Useful if you also use Prototype or MooTools.)
  • [Wayback/Archive] What does the dot after dollar sign mean in jQuery when declaring variables? – Stack Overflow

    Q

    I see variables declared as:
    $.root = $("body");
    
    and
    $root = $("body");
    
    What is the difference between the two?

    A (thanks [Wayback/Archive] Sampson)

    Functions in JavaScript are objects. And like most objects in JavaScript, you can arbitrarily add properties to them. The $ function is just that, a function. So if you want to pop a property onto it and reference a jQuery collection, or reference, you can.
    By adding the collection as a property on the $ function, it is one less variable in the current scope. You can examine the keys of the jQuery function before and after if you’d like to see how it affects the function’s topography and (enumerable) property list:
    Object.keys($);
    // ["fn", "extend", "expando"..."parseHTML", "offset", "noConflict"]
    
    $.root = $("body");
    // [<body>]
    
    Object.keys($);
    // ["fn", "extend", "expando"..."parseHTML", "offset", "noConflict", "root"]
    

     

jQuery documentation

  • [Wayback/Archive] jQuery() | jQuery API Documentation – returning an empty set

    Returning an Empty Set

    Calling the jQuery() method with no arguments returns an empty jQuery set (with a .length property of 0). Similarly, if an argument of nullundefined, an empty array ([]), or an empty string ("") is passed, the set contains no elements.
  • [Wayback/Archive] .jquery | jQuery API Documentation
    The .jquery property is assigned to the jQuery prototype, commonly referred to by its alias $.fn. It is a string containing the version number of jQuery, such as “1.5.0” or “1.4.4”.

    Examples:

    Determine if an object is a jQuery object
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    var a = { what: "A regular JS object" },
    b = $( "body" );
    if ( a.jquery ) { // Falsy, since it's undefined
    alert( "a is a jQuery object!" );
    }
    if ( b.jquery ) { // Truthy, since it's a string
    alert( "b is a jQuery object!" );
    }
    Get the current version of jQuery running on the page
    1
    alert( "You are running jQuery version: " + $.fn.jquery );
  • [Wayback/Archive] Types | jQuery API Documentation: Prototype

    Prototype

    All objects have a prototype property. Whenever the interpreter looks for a property, it also checks in the object’s prototype if the property is not found on the object itself. jQuery uses the prototype extensively to add methods to jQuery instances. Internally, jQuery makes jQuery.fn an alias of jQuery.prototype so you can use either one (though plugin developers have standardized on fn).
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    var form = $("#myform");
    console.log( form.clearForm ); // undefined
    // jQuery.fn === jQuery.prototype
    jQuery.fn.clearForm = function() {
    return this.find( ":input" ).each(function() {
    this.value = "";
    }).end();
    };
    // works for all instances of jQuery objects, because
    // the new method was added to the prototype
    console.log( form.clearForm ); // function
    form.clearForm();
  • [Wayback/Archive] jQuery.fn.extend() | jQuery API Documentation

    The jQuery.fn.extend() method extends the jQuery prototype ($.fn) object to provide new methods that can be chained to the jQuery() function.

    This seems to be a construction that lots of people use to shoehorn truckloads of functionality into an almost global context. Doing that requires careful naming of each method, which the example does not make clear.

    A really important jQuery documentation problem is the lack of a separate documentation entry stating jQuery.fn = jQuery.prototype which is in the source code (more recent versions have it on different lines):
  • [Wayback/Archive] jQuery.noConflict() | jQuery API Documentation
    Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery’s case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.
    If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict( true ) from the second version will return the globally scoped jQuery variables to those of the first version.
    If necessary, you can free up the jQuery name as well by passing true as an argument to the method. This is rarely necessary, and if you must do this (for example, if you need to use multiple versions of the jQuery library on the same page), you need to consider that most plug-ins rely on the presence of the jQuery variable and may not operate correctly in this situation.
  • [Wayback/Archive] jQuery – MDN Web Docs Glossary: Definitions of Web-related terms | MDN
    jQuery is a JavaScript Library that focuses on simplifying DOM manipulation, AJAX calls, and Event handling.
    jQuery uses a format, $(selector).action() to assign an element(s) to an event. To explain it in detail, $(selector) will call jQuery to select selector element(s), and assign it to an event API called .action().
    Before writing this post, I had no idea what jQuery was and why it had the word Query in the name (I wrongly associated it with a server-side JavaScript SQL library).

JavaScript documentation

  • [Wayback/Archive] Object prototypes – Learn web development | MDN

    Prototypes are the mechanism by which JavaScript objects inherit features from one another.

    Every object in JavaScript has a built-in property, which is called its prototype. The prototype is itself an object, so the prototype will have its own prototype, making what’s called a prototype chain. The chain ends when we reach a prototype that has null for its own prototype.

    Prototypes are a powerful and very flexible feature of JavaScript, making it possible to reuse code and combine objects.
    In particular they support a version of inheritance. Inheritance is a feature of object-oriented programming languages that lets programmers express the idea that some objects in a system are more specialized versions of other objects.
  • [Wayback/Archive] Object – JavaScript | MDN

    Nearly all objects in JavaScript are instances of Object; a typical object inherits properties (including methods) from Object.prototype, although these properties may be shadowed (a.k.a. overridden). However, an Object may be deliberately created for which this is not true (e.g. by [Wayback/Archive] Object.create(null)), or it may be altered so that this is no longer true (e.g. with [Wayback/Archive] Object.setPrototypeOf).

    Changes to the Object prototype object are seen by all objects through prototype chaining, unless the properties and methods subject to those changes are overridden further along the prototype chain. This provides a very powerful although potentially dangerous mechanism to override or extend object behavior.
  • [Wayback/Archive] javascript – How does the “this” keyword work? – Stack Overflow has a few very precise and elaborate answers. Too much to quote here so I just thank these people:

Note $ is used to prefix variables too

[Wayback/Archive] jquery – Why use $ (dollar sign) in the name of javascript variables? – Stack Overflow (thanks [Wayback/Archive] Simon and [Wayback/Archive] Konerak):

The $ in the variable name is only part of the name, but the convention is to use it to start variable names when the variable represents a jQuery object.
var $myHeaderDiv = $('#header');
var myHeaderDiv = document.getElementById('header');
Now later in your code, you know the $myHeaderDiv is already a jQuery object, so you can call jQuery functions:
$myHeaderDiv.fade();

To get from the DOM-variable to the jQuery variable:

var $myHeaderDiv = jQuery(myHeaderDiv); //assign to another variable
jQuery(myHeaderDiv).fade(); //use directly

//or, as the $ is aliased to the jQuery object if you don't specify otherwise:
var $myHeaderDiv = jQuery(myHeaderDiv); //assign
$(myHeaderDiv).fade(); //use

To get from the jQuery variable to the DOM-variable.

var myHeaderDiv = $myHeaderDiv.get(0);

Finding the jQuery version

Via [Wayback/Archive] detect jquery version – Google Search:

Via [Wayback/Archive] jquery fn – Google Search:

–jeroen

Posted in Development, JavaScript/ECMAScript, jQuery, Scripting, Software Development, Web Development | Leave a Comment »