Citat:
Ursprungligen postat av
SuperPutte
Kastar ut frågan till de som varit inblandade i utvecklingen av Flasher:
Kommer det någon uppdatering som är anpassad till senaste Flashback? Det jag personligen saknar mest är autoloadpage-funktionen som Anteus bidrog med.
Tog bort allt utom autoloadpage-funktionen och fixade den för nya designen(förhoppningsvis utan css-strul)
Kod:
// ==UserScript==
// @name Flashback oändlig bläddring
// @author Leif-Bengt Viktor & Anteus. Minimoddad av Splitface
// @description Laddar nästa sida nedanför aktuell sida så länge det är möjlig + ersatt flashback.org/leave.php i länkar och satt unvis-länkar för diverse medie-siter
// @include https://www.flashback.org/*
// @version 0.5
// @grant none
// ==/UserScript==
function initiateFlasher(arg) {
if (arg) {
$ = arg;
}
var ajaxQueue = [],
processAjaxQueue = function () {
if (ajaxQueue.length > 0) {
for (ajax in ajaxQueue) {
var obj = ajaxQueue[ajax];
try {
GM_xmlhttpRequest(obj);
} catch (e) {}
}
ajaxQueue = [];
}
},
Flasher = {};
setInterval(function () {
processAjaxQueue();
}, 0); //100
function gmAjax(obj) {
ajaxQueue.push(obj);
}
Flasher.defaultSettings = {
autoLoadPage: {
value: true,
label: 'Ladda nästa sida',
html: '<input type="checkbox"/>'
},
bytasida: {
value: true,
label: 'Höger-/Vänsterpil för att byta sida',
html: '<input type="checkbox"/>'
},
unvis: {
value: true,
label: 'Lägg till unvis.it framför vissa tidningars webbsidor',
html: '<input type="checkbox"/>'
}
};
Flasher.currentSettings = {};
Flasher.init = function (refresh) {
if (!refresh) {
Flasher.setupSettings();
Flasher.setupStatus();
}
//Flasher.setupCacheVars();
Flasher.setupCacheCollections();
if (Flasher.status.isTopic) {
Flasher.setupUnvis();
Flasher.fixLeaveLinks();
if (!refresh) {
$('a[title*="Nästa sida"]:first').attr('title', 'Nästa sida');
Flasher.setupAutoLoadPage();
}
}
};
Flasher.setupSettings = function () {
$.each(Flasher.defaultSettings, function (key, value) {
Flasher.currentSettings[key] = {
label: Flasher.defaultSettings[key].label,
html: Flasher.defaultSettings[key].html
};
var userChoice = localStorage.getItem(key),
choice;
if (userChoice !== null) {
choice = userChoice;
} else {
choice = Flasher.defaultSettings[key].value;
}
if (typeof choice === 'string') {
if (choice.match(/true/i)) {
Flasher.currentSettings[key].value = true;
} else if (choice.match(/false/i)) {
Flasher.currentSettings[key].value = false;
} else if (choice.match(/^[0-9]+$/i)) {
Flasher.currentSettings[key].value = parseInt(choice, 10);
} else {
Flasher.currentSettings[key].value = choice;
}
} else {
Flasher.currentSettings[key].value = choice;
}
});
};
Flasher.setupAutoLoadPage = function () {
$(window).scroll(function () {
if ($(window).scrollTop() > $(document).height() - $(window).height() - 500 && !Flasher.isFetchingNewPage) {
Flasher.isFetchingNewPage = true;
var $next = $('a[title*="Nästa sida"]:last');
if ($next.length && $next.attr('href').length > 1) {
var nextUrl = window.location.protocol + '//' + window.location.hostname + $next.attr('href');
$.ajax({
url: nextUrl,
success: function (html) {
var $newDom = $(html);
$('.row.row-forum-toolbar:last').html($newDom.find('.row.row-forum-toolbar:last').html());
var nextsidenavbar = $newDom.find('.row.row-forum-toolbar').html();
$('div').filter('#posts:last').after('<div id="posts">' + '<br>' + nextsidenavbar + '<br><br></div>');
$('a[title*="Nästa sida"]:eq(-0)').attr('title', '');
$('div').filter('#posts:last').after($newDom.find('#posts'));
window.history.pushState('', document.title, nextUrl);
Flasher.isFetchingNewPage = false;
Flasher.init(true);
},
error: function () {
if (callback) {
callback('error');
}
}
});
}
}
});
};
Flasher.setupStatus = function () {
Flasher.status = {
isTopic: $('div#posts').eq(0).length
};
};
Flasher.setupCacheCollections = function () {
Flasher.collection = {
a: $('.post, .panel, #collapseobj_threadreview').find('a[href*="http"]')
};
};
Flasher.fixLeaveLinks = function () {
Flasher.collection.a.filter('a[href*="leave.php"]').each(function (index) {
try {
var newHref = $(this).attr('href').replace(/.*leave.php?\?u=/, '').replace(/%26amp%3B/g, '&');
$(this).attr('href', decodeURIComponent(newHref.replace(/\+/g, " ")));
} catch (e) {}
});
};
Flasher.setupUnvis = function () {
if(Flasher.currentSettings.unvis.value){
var sites = ["aftonbladet.se", "expressen.se", "dn.se", "svt.se", "svd.se", "sverigesradio.se","sydsvenskan.se"];
for(var i=0; i < sites.length; i++){
Flasher.collection.a.filter('a[href*="' + sites[i] + '"]').each(function (index) {
if($(this).attr('href').indexOf('unvis') == -1){
try{
if($(this).attr('href').indexOf('sverigesradio') > -1){
var newHref = $(this).attr('href').replace('sverigesradio', 'unvis.it/sverigesradio');
$(this).attr('href', decodeURIComponent(newHref));
}
if($(this).attr('href').indexOf('sydsvenskan') > -1){
var newHref = $(this).attr('href').replace('sydsvenskan', 'unvis.it/sydsvenskan');
$(this).attr('href', decodeURIComponent(newHref));
}
var newHref = $(this).attr('href').replace('www.', 'unvis.it/www.');
$(this).attr('href', decodeURIComponent(newHref));
} catch (e) {}
}
});
}
}
};
Flasher.init();
}
function addScript(callback) {
var script = document.createElement('script');
script.text = '(' + callback.toString() + ')();';
document.body.appendChild(script);
}
if (typeof unsafeWindow !== 'undefined' && unsafeWindow.jQuery) {
initiateFlasher(unsafeWindow.jQuery);
} else {
addScript(initiateFlasher);
}