TL;DR:
javascript:{h=location.href;open('https://archive.is/?run=1&url='+encodeURIComponent(h));location.href='https://web.archive.org/save/'+(h)}
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)}
Posted in Bookmarklet, Development, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers, Web Development | Leave a Comment »
Posted by jpluimers on 2023/08/15
This is a follow-up to Bookmarklets for Archive.is and the WayBack Machine to go to the original page.
Archive.is has two kinds of URLs:
You get the first URL both after archiving and when browsing from an archived page to another archived page (if it is not archived you will go the unarchived full page URL).
Posted in archive.is / archive.today, Development, Internet, InternetArchive, JavaScript/ECMAScript, Power User, Scripting, Software Development, WayBack machine | Leave a Comment »
Posted by jpluimers on 2023/07/26
Since I will likely need this one day:
jQuerify Bookmarklet | Learning jQuerySearching 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.
$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.
$is just a shortcut forjQuery. 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 forjQuery, you can usenoConflictand the library will restore$to whatever it was before jQuery took it over. (Useful if you also use Prototype or MooTools.)
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"]
Returning an Empty Set
Calling thejQuery()method with no arguments returns an empty jQuery set (with a.lengthproperty of 0). Similarly, if an argument ofnull,undefined, an empty array ([]), or an empty string ("") is passed, the set contains no elements.
.jquery | jQuery API DocumentationThe.jqueryproperty is assigned to the jQuery prototype, commonly referred to by its alias$.fn. It is a string containing the version number ofjQuery, such as “1.5.0” or “1.4.4”.Examples:
Determine if an object is a jQuery object
12345678910var a = { what: "A regular JS object" },b = $( "body" );if ( a.jquery ) { // Falsy, since it's undefinedalert( "a is a jQuery object!" );}if ( b.jquery ) { // Truthy, since it's a stringalert( "b is a jQuery object!" );}Get the current version of jQuery running on the page
1alert( "You are running jQuery version: " + $.fn.jquery );
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 makesjQuery.fnan alias ofjQuery.prototypeso you can use either one (though plugin developers have standardized onfn).
1234567891011121314var form = $("#myform");console.log( form.clearForm ); // undefined// jQuery.fn === jQuery.prototypejQuery.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 prototypeconsole.log( form.clearForm ); // functionform.clearForm();
The
jQuery.fn.extend()method extends the jQuery prototype ($.fn) object to provide new methods that can be chained to thejQuery()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.
jQuery.fn = jQuery.prototype which is in the source code (more recent versions have it on different lines):jQuery.fn = jQuery.prototype = { // The current version of jQuery being used jquery: version,
// The current version of jQuery being used
jquery: "@VERSION",
Many JavaScript libraries use$as a function or variable name, just as jQuery does. In jQuery’s case,$is just an alias forjQuery, 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 thejQueryname as well by passingtrueas 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 thejQueryvariable and may not operate correctly in this situation.
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 selectselectorelement(s), and assign it to an event API called.action().
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
nullfor 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.
Nearly all objects in JavaScript are instances of
Object; a typical object inherits properties (including methods) fromObject.prototype, although these properties may be shadowed (a.k.a. overridden). However, anObjectmay 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 theObjectprototype 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.
$ 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$myHeaderDivis 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(); //useTo get from the jQuery variable to the DOM-variable.
var myHeaderDiv = $myHeaderDiv.get(0);
jQuery versionVia [Wayback/Archive] detect jquery version – Google Search:
if (typeof jQuery != 'undefined') { // jQuery is loaded => print the version alert(jQuery.fn.jquery); }no
There are 2 ways to check currently loaded jquery version:
jQuery.fn.jqueryandjQuery().jquery(shorthands:$.fn.jquery$().jquery). I wrote about it in details with links to jquery source code if you’d like to dig deeper
jQuery.fn = jQuery.prototype = {// The current version of jQuery being usedjquery: version,
Don’t use
jQuery().jquery. It creates a jQuery object for nothing, just use what the answer says.– user9016207
Via [Wayback/Archive] jquery fn – Google Search:
jQuery.fn mean? – Stack Overflow (thanks [Wayback/Archive] ajsie and [Wayback/Archive] Andy E)jQuery.fn = jQuery.prototype = { // ... }That meansjQuery.fn.jqueryis an alias forjQuery.prototype.jquery, which returns the current jQuery version. Again from the source code:// The current version of jQuery being used jquery: "@VERSION",
jQuery.fn = jQuery.prototype = {
// The current version of jQuery being used
jquery: "@VERSION",
for the cases where your page is loading with other javascript libraries like mootools that are conflicting with the$symbol, you can usejQueryinstead.For instance,jQuery.fn.jqueryorjQuery().jquerywould work just fine:
–jeroen
Posted in Development, JavaScript/ECMAScript, jQuery, Scripting, Software Development, Web Development | Leave a Comment »
Posted by jpluimers on 2023/07/20
Maintaining a blog takes considerable time, so I wrote a bit of JavaScript for the browser console and bookmarklets to help me navigate faster, especially from my published posts on wiert.me back to the WordPress editing environment.
I wrote this because a query like [Wayback/Archive] wordpress get id from post html – Google Search top hits only contain results that work within the WordPress environment itself, like for instance [Wayback/Archive] 14 Ways to Get Post ID in WordPress.
This blog post is long and contains a lot of information, so I have split it in quite a few sections.
Let’s get started:
Posted in Bookmarklet, Classic editor, Development, Gutenberg editor, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers, Web Development | Leave a Comment »
Posted by jpluimers on 2023/06/27
I need to check out [Wayback/Archive.is] The Time Travel Debugger for Web Development:
one frame of the replay.io demo
Posted in Development, JavaScript/ECMAScript, Scripting, Software Development | 1 Comment »
Posted by jpluimers on 2023/06/14
Based on [Wayback/Archive] javascript – how to refresh an iframe automatically – Stack Overflow and help from [Archive] Roderick Gadellaa (@RGadellaa) / Twitter, I used this JavaScript code right after the body in the html page to reload part of the iframes every 3 minutes and another part every 3 hours:
<script> var iframes3minuteInterval = setInterval( () => { const ids3minutes = [ 'agenda_iframe', 'month_iframe' ]; ids3minutes.forEach( id => { element = document.getElementById( id ); element.src = element.src; }); }, 1000 * 60 * 3); var iframes3hourInterval = setInterval( () => { const ids3hours = [ 'weerplaza_nederland_iframe', 'weerplaza_radar_iframe', 'buienradar_iframe' ]; ids3hours.forEach( id => { element = document.getElementById( id ); element.src = element.src; }); }, 1000 * 60 * 60 * 3); </script>
The iframes are widgets for:
This was to workaround GitLab pages on a custom domain are nice, but be aware of intermittent 502 and certificate errors. Now the page only gets loaded once, and the widgets at intervals that are needed.
—jeroen
Posted in CSS, Development, HTML, JavaScript/ECMAScript, Scripting, Software Development, Web Development | Leave a Comment »
Posted by jpluimers on 2023/06/08
In Bookmarklets for Archive.is and the WayBack Machine to go to the original page, I wrote about how the Shadow DOM is used to prevent side effects between the code of the WayBack machine and the archived page.
In a similar manner, Bookmarklets can also interfere with code on the page and vice versa, for instance by using global variables.
That is why the [Wayback/Archive] A simple bookmarklet to tweet the current page – DEV Community is wrapped in a special kind of function:
javascript:(function(){ n=getSelection().anchorNode; t=n.nodeType===3?n.data:n.innerText;t='“'+t+'”\\n\\n'; window.open(`https://twitter.com/intent/tweet? text=${encodeURIComponent(t)}${document.location.href}`) })()
This is an [Wayback/Archive] IIFE – MDN Web Docs Glossary: Definitions of Web-related terms | MDN or “Immediately Invoked Function Expression”, a mechanism coined by [Archive] Ben Alman (@cowboy) / Twitter at [Wayback/Archive] Ben Alman » Immediately-Invoked Function Expression (IIFE).
Since the variables are inside the function body, they won’t interfere with the page. The body will be immediately executed.
Related:
–jeroen
Posted in Bookmarklet, Development, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers | Leave a Comment »
Posted by jpluimers on 2023/06/07
Quite often, when browsing an archived page on Archive.is or the WayBack Machine, I want to check the current status of the original page.
So I wrote a few Bookmarklets.
Any Archive.is page has a Saved from field which is an input html element having a name attribute with value q and a value property containing the URL, which is navigated to by assigning the location in the above code.
So my goto Bookmarklet is this one:
javascript:open(document.getElementsByName("q")[0]?.value)
It uses [0]? as there is no getElementsByName, but there is [Wayback/Archive] Document.getElementsByName() – Web APIs | MDN as name values need not to be unique but id values have to be.
The above works on all types of Archive.is page types:
Saved from field.Saved from and Redirected from fields.Saved from and Redirected from, the fields Via and Original also are added.To get the additional fields from the other fields, we need to figure out a way to access them.
Posted in Bookmarklet, Development, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers | 1 Comment »