// ==UserScript== // @name GetRec'd: AO3 dev // @namespace http://archiveofourown.org // @description adds recommendations to archiveofourown.org // @include http://archiveofourown.org/works/* // @exclude http://archiveofourown.org/works/search* // @version 1.3 // @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; var tags = { character: [], additional: [] }; var category = []; var workData = {}; var title = $('#workskin .preface h2.title').text(); $('#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(); }); fillArr('.kudos a:not(#kudos_summary, #kudos_collapser)', usersAll); fillArr('.meta .fandom ul li a.tag', category); fillArr('dd.character.tags ul li a.tag', tags.character); fillArr('dd.relationship.tags ul li a.tag', tags.character); fillArr('dd.freeform.tags ul li a.tag', tags.additional); if (usersAll.length > 5000) { users = usersAll.slice(0, 5000); } else { users = usersAll; } workData.users = users; workData.title = title; workData.category = category; workData.tags = tags; $.post('http://localhost:5000', workData).done(function(res) { var data = JSON.parse(res); 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 +'

'); }); } }); }); function fillArr(selector, arr) { $(selector).each(function () { arr.push($(this).text()); }); } })();