// ==UserScript== // @name GetRec'd: AO3 // @namespace http://archiveofourown.org // @description adds recommendations to archiveofourown.org // @include http://archiveofourown.org/works/* // @exclude http://archiveofourown.org/works/search* // @version 1.0 // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @grant none // @downloadURL none // ==/UserScript== /***** A note on privacy: This script sends data about the AO3 work you are veiwing to a web server where it is stored in a database. This process is anoymous and no information about you or your habits are collected. Project blog: get-recd.tumblr.com *****/ (function() { 'use strict'; $(document).ready(function(){ var usersAll = []; var users; $('#workskin') .append('


') .find('#rec-box') .toggle(false); $('#feedback ul.actions:nth-of-type(1)') .prepend('You might also like...') .on('click', '#rec-button', function(){ console.log('click!'); $('#rec-box').toggle(); }); $('.kudos a:not(#kudos_summary, #kudos_collapser)').each(function () { usersAll.push($(this).text()); }); if ( usersAll.length < 8 ) { $('#rec-box').append('

No recs yet! More users need to leave kudos on this work.

'); } else { var title = $('#workskin .preface h2.title').text(); var category = []; $('.meta .fandom ul li a.tag').each(function () { category.push($(this).text()); }); if (usersAll.length > 5000) { users = usersAll.slice(0, 5000); } else { users = usersAll; } var workData = { users: users, name: title, category: category }; $.post('https://intense-reef-64978.herokuapp.com/', workData).done(function(res) { var data = JSON.parse(res); console.log('loaded'); console.log('res',res); console.log('data', data); var message = data.fail; if (data.fail && !message) { $('#rec-box') .append('

Oops! Something went wrong :(


Report a problem'); } else if (message){ $('#rec-box') .append('

Oops! ' + message + '


Report a problem'); } else { $(data.data).each(function() { var recID = this._id; var recTitle = this.name; var recCategory = this.category; $('#rec-box') .append('

' + recTitle + '

' + recCategory +'

'); }); } }); } }); })();