Discussions » Creation Requests

[ignorant] please help with simple userscript, larger images for pinterest's standalone images

§
Posted: 2016-11-14

[ignorant] please help with simple userscript, larger images for pinterest's standalone images

Here's what I came up with, that essentially works:

// ==UserScript==
// @name pinterest originals
// @namespace // @namespace https://s-media-cache-k0.pinimg.com
// @include https://s-media-cache-ak0.pinimg.com/(/\/\d\d\dx\//)*
// @exclude https://s-media-cache-ak0.pinimg.com/originals/*
// @version 1
// @grant none
// ==/UserScript==

document.location.replace(document.location.href.replace(/\/\d\d\dx\//, "/originals/"))

The problem is that it apparently sort of loops infinitely or something, even though it's not immediately obvious on firefox. If the image is big, zoomed out to fit to the window, and you want to zoom in to original/ful size, it will immediately zoom out to fit in the window size again. With chrome/tampermonkey it seems that the infinite loop is more obvious. I tried the easy way out of adding the full size url as an exclude, but it didn't work.

It also goes kind of crazy if there's no "originals" size available.

Ideally it would be more or less like this other, actual, script:


// ==UserScript==
// @name Tumblr Image Size
// @description When directly viewing an image on Tumblr, ensures that the highest resolution image is loaded.
// @namespace http://userscripts.org/users/543210
// @include /^https?://\d+\.media\.tumblr\.com/(.+/)*tumblr_.+_\d+\.(jpe?g|gif|png|bmp)$/
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant none
// ==/UserScript==

var sizes = [ '_1280.', '_500.', '_400.', '_250.', '_100.' ];

function checkSize(index) {
if (index >= sizes.length) return;
var url = window.location.href.replace(/(.*(?=_))(_\d*.)(.*)/, '$1' + sizes[index] + '$3');
if (url == window.location.href) return;
$.ajax({
url: url,
type: 'HEAD',
success: function(data, textStatus, jqXHR) {
window.location.replace(url);
},
error: function(jqXHR, textStatus, errorThrown) {
checkSize(index + 1);
}
});
}

But I'm absolutely ignorant in this whole thing and I'm failing miserably in my attempts at adapting the second one to the pinterest URL regex/whatnot.

The other possible sizes for pinterest would be 1200x, 750x, 736x, 600x, 564x, 550x, and probably a few more below that but I don't know any other besides 236x, and then there's no point in doing anything.


Thanks.

Post reply

Sign in to post a reply.