Skip to content

Instantly share code, notes, and snippets.

@XtinaSchelin
Last active July 31, 2020 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XtinaSchelin/afa13f2f814fee08c533f825ebfbbb94 to your computer and use it in GitHub Desktop.
Save XtinaSchelin/afa13f2f814fee08c533f825ebfbbb94 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AO3: Shake Gift
// @namespace https://xtinas.org
// @match *://*.archiveofourown.org/*
// @homepageUrl https://gist.github.com/XtinaSchelin/afa13f2f814fee08c533f825ebfbbb94
// @version 1.0.0.0
// @grant none
// ==/UserScript==
// FIXME: Handle if there isn't already a .actions item in the work list object.
(function($) {
$(document).ready(function() {
if ( !$('body').hasClass('logged-in') ) { return; }
var $base_url = "https://archiveofourown.org/collections/$COLLECTION$/works?commit=Sort+and+Filter&work_search%5Bquery%5D=id%3A$ID$";
var $main = $( '#main' );
var $thurl = "";
$('.index.group li.work', $main).each( function() {
var work_id = this.id.replace('work_', '');
var collection = "";
if ( work_id !== '' ) {
var $dove = $('div.mystery', this);
if ($dove.length > 0)
{
collection = $('h5 a', this)[0].getAttribute("href").split("/")[2];
$thurl = $base_url.replace("$COLLECTION$", collection).replace("$ID$", work_id);
$('.actions', this).prepend('<a style="float: left; left: 10px; position: absolute;" href="' + $thurl + '">Shake Gift</a>');
}
}
});
});
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment