Skip to content

Instantly share code, notes, and snippets.

@Seklfreak
Last active January 18, 2018 15:42
Show Gist options
  • Save Seklfreak/bc938b3200bb4d8d1ced0eca60a4109e to your computer and use it in GitHub Desktop.
Save Seklfreak/bc938b3200bb4d8d1ced0eca60a4109e to your computer and use it in GitHub Desktop.
tistory fixes
// ==UserScript==
// @name tistory fixes
// @namespace https://slmn.de
// @version 1.3
// @description various fixes for tistory blogs
// @author Sebastian Winkler
// @match http://*.tistory.com/*
// @match http://19951218.net/*
// @match http://www.wikplayer.com/*
// @exclude http://cfile*.uf.tistory.com/*
// @grant GM_registerMenuCommand
// @grant GM_download
// @grant GM_notification
// @connect cfile*.uf.tistory.com
// ==/UserScript==
(function() {
'use strict';
// Redirect mobile site to desktop version
var currentUrl = window.location.href;
if (currentUrl.match('/m/')) {
window.location.replace(currentUrl.replace('/m/', '/'));
}
var rxDaumcdnTistory = /^http(s?):\/\/img[0-9]\.daumcdn\.net\/thumb\/[^\/]+\/\?scode=mtistory&fname=(http(s?)%3A%2F%2F[a-z0-9]+\.uf.tistory.com%2F(image|original)%2F[A-Z0-9]+)$/;
var imageElements = document.getElementsByTagName('img');
for (var i = 0; i < imageElements.length; i++) {
var newImageSrc = imageElements[i].src;
if(imageElements[i].hasAttribute('srcset')) {
imageElements[i].removeAttribute('srcset');
}
if(newImageSrc.match(rxDaumcdnTistory) instanceof Array) {
newImageSrc = decodeURIComponent(newImageSrc.replace(rxDaumcdnTistory, "$2"));
imageElements[i].src = newImageSrc;
}
if(imageElements[i].src.match('uf.tistory.com/image/')) {
newImageSrc = imageElements[i].src.replace('/image/', '/original/');
imageElements[i].src = newImageSrc;
}
}
var hasImageToDownload = false;
var newImageUrl;
var downloadedImages = 0;
for (i = 0; i < imageElements.length; i++) {
if(isWantedElement(imageElements[i])) {
hasImageToDownload = true;
break;
}
}
if (hasImageToDownload === true) {
GM_registerMenuCommand('download original images', function() {
var imageElements = document.getElementsByTagName('img');
var newImageUrl;
var downloadedImages = 0;
for (var i = 0; i < imageElements.length; i++) {
if(isWantedElement(imageElements[i])) {
downloadedImages++;
newImageUrl = imageElements[i].src.replace('/image/', '/original/');
GM_download(newImageUrl, imageElements[i].getAttribute('filename'));
//console.debug("url: " + newImageUrl + ", filename:" + imageElements[i].getAttribute('filename'));
}
}
GM_notification('started ' + downloadedImages + ' downloads');
}, 'r');
}
})();
function isWantedElement(element) {
if((element.src.match('uf.tistory.com/image/') || element.src.match('uf.tistory.com/original/')) &&
element.getAttribute('filename') !== null) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment