// ==UserScript==
// @name Imgur Old Design
// @namespace 24e9d0d286ee3808d404284e82e564c49c6704bb
// @version 0.5
// @description Restores the old imgur Home page
// @author /u/AyrA_ch
// @match https://imgur.com/
// @match https://imgur.com/gallery/*
// @grant none
// @run-at document-start
// ==/UserScript==
// Changelog
// 0.5: Implement new behavior to switch to the old design
// 0.4: Detect reload loops and silently stop reloading
// 0.3: Support new "postpagebeta(logged)" cookie
// 0.2: Support new "frontpagebetav2" cookie
// 0.1: Support "frontpagebeta" cookie
(function () {
'use strict';
//Extract all cookies
var cookies = document.cookie.split("; ").map(function (v) {
var eq = v.indexOf('=');
return {
name: v.substr(0, eq),
value: decodeURIComponent(v.substr(eq + 1))
};
});
var setCookie = function (name, value) {
value = encodeURIComponent(value);
//Get frontpage cookie
var fp = cookies.filter(function (v) {
return v.name === name
})[0];
var past = (new Date(2000, 0, 1)).toUTCString();
var future = (new Date(2032, 0, 1)).toUTCString();
//Overwrite/create cookie if needed
if (fp === undefined || fp.value !== value) {
//Delete existing cookie first
document.cookie = name + "=0; Domain=imgur.com; Expires=" + past;
document.cookie = name + "=0; Domain=.imgur.com; Expires=" + past;
//Create new cookie
document.cookie = name + "=" + value + "; Domain=.imgur.com; Path=/; Expires=" + future;
return true;
}
return false;
};
var isReloadTrap = function () {
var cookie = cookies.filter(function (v) {
return v.name === "reloadtrap"
})[0];
return cookie && 3 < +cookie.value;
};
var setReloadTrap = function () {
var cookie = cookies.filter(function (v) {
return v.name === "reloadtrap"
})[0];
var value = cookie ? +cookie.value + 1 : 1;
document.cookie = "reloadtrap=" + value + "; domain=.imgur.com; expires=" + (new Date(Date.now() + 10000)).toUTCString();
};
var set = false;
set = setCookie("frontpagebeta", "0") || set;
set = setCookie("frontpagebetav2", "0") || set;
set = setCookie("postpagebeta", "0") || set;
set = setCookie("postpagebetalogged", "0") || set;
set = setCookie("switching_from_spa_to_legacy", "1") || set;
if (set) {
if (!isReloadTrap()) {
if (window.stop) {
window.stop();
}
setReloadTrap();
location.reload();
} else {
//alert("We keep getting trapped in a reload loop");
}
}
})();
/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.
DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/