Raw Source
lennarn / Automatically view all steps of an Instructable

// ==UserScript==
// @name        Automatically view all steps of an Instructable
// @namespace   lennarn-instructables-allsteps
// @include http://instructables.com/id/*
// @include http://www.instructables.com/id/*
// @version     1.0
// @description  Redirect to instructables.com/id/*/?ALLSTEPS if not already there
// @downloadURL https://openuserjs.org/install/lennarn/Instructables-allsteps.user.js
// @author       Lennart Nilsen
// @grant none
// @run-at document-start
// ==/UserScript==
 
var url = window.location.href;
var strlen = url.length;
var allsteps = "?ALLSTEPS";
var redir = url;

// Count slashes in url-1. 
// if more than 5 we are on a substep page. 
// 2 in http://, 1 after id/, 1 after document-name.
var slashes = 0;
for (i = 0; i < strlen; i++) {
    if (url.substring(i,i+1) == "/")
        slashes++;
}

if (slashes <= 5) { 
    if (url.substring(strlen-9, strlen) != allsteps) { //the url doesn't end in ?ALLSTEPS
        
        
        if (url.substring(strlen-1,strlen) == "/") { // the last character in url is /
            redir = url + allsteps; 
        }
        else { // the last character in url is not /
            redir = url + "/" + allsteps;
        }
        window.location.assign(redir);
    } // ELSE we have reached our goal
} else { // we are on a substep page
    //user choice: view all steps? Y/N 
    if (window.confirm("You are on a step page. View all steps?")) {
        url = url.substr(7,url.length);
        var urlarray = url.split("/");
        redir = "http://";
        for (i = 0; i < 3; i++) {
            redir = redir.concat(urlarray[i] + "/");
        }
        redir = redir.concat(allsteps);
        window.location.assign(redir);
    }
}