Greasy Fork

FIMFiction - Random Story

Adds a button to random jump to a story page. You need to refresh the number of stories manually.

目前为 2014-09-29 提交的版本。查看 最新版本

// ==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.
// ==/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('<div class="user_drop_down_menu"><a href="/story/' + randomstory + '" id="randomstoryButton" class="button"><i class="fa fa-book"></i><span>Random Story</span></a><div class="menu_list"><a href="javascript:void()" class="button" id="refbtn"><i class="fa fa-refresh"></i><span>Refresh (' + numberofstories + ')</span></a></div></div>');

$("#refbtn").click(function() {
	$("#refbtn").html('<i class="fa fa-refresh"></i><span>Refreshing...</span>');
	$.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('<i class="fa fa-refresh"></i><span>Refresh (' + numberofstories + ')</span>');
	});
});