// ==UserScript== // @name FIMFiction - Random Story // @namespace Selbi // @include http*://*fimfiction.net/* // @version 1.1 // @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()); $(".inner:first a:last").after('
Random Story
'); $("#refbtn").click(function() { $("#refbtn").html('Refreshing...'); $.get("//www.fimfiction.net/stories/latest", function(source) { var newstories = $(".views:first", source).attr("data-story"); if (newstories > numberofstories || newstories.length > numberofstories.length) { numberofstories = newstories; GM_setValue("storycount", numberofstories); } randomstory = Math.floor(numberofstories * Math.random()); $("#randomstoryButton").attr("href", '/story/' + randomstory); $("#refbtn").html('Refresh (' + numberofstories + ')'); }); });