// ==UserScript== // @name FIMFiction - Random Story // @namespace Selbi // @include http*://*fimfiction.net/* // @version 1.2 // @require http://code.jquery.com/jquery-1.11.0.min.js // @grant GM_setValue // @grant GM_getValue // @description Adds a button to random jump to a story page. You need to refresh the number of stories manually. // @downloadURL none // ==/UserScript== //GM_deleteValue("storycount"); var numberofstories = GM_getValue("storycount"); var randomstory = 0; if (numberofstories == undefined) numberofstories = "Click!"; randomstory = Math.floor(numberofstories * Math.random()); var newstories = 0; $(".inner:first a:last").after('
'); $("#refbtn").click(function() { $("#refbtn").html('Refreshing...'); $.get("//www.fimfiction.net/stories/latest", function(source) { $(".button_add_story_to_group", source).each(function(){ var storyid = $(this).attr("data-story"); if (+storyid > +newstories) newstories = storyid; }); if (+newstories > +numberofstories) { var storydifference = newstories - numberofstories; numberofstories = newstories; GM_setValue("storycount", numberofstories); } randomstory = Math.floor(numberofstories * Math.random()); $("#randomstoryButton").attr("href", '/story/' + randomstory); if (storydifference == 0 || storydifference == undefined) storydifference = "No"; $("#refbtn").html('Refresh (' + numberofstories + ') [' + storydifference + ' new]'); }); });