Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active May 13, 2016 21:11
Show Gist options
  • Save stephanieleary/d455dcaea1806a4229a95cf1a8abb238 to your computer and use it in GitHub Desktop.
Save stephanieleary/d455dcaea1806a4229a95cf1a8abb238 to your computer and use it in GitHub Desktop.
$('li.blurb').each(function(index) {
var chapters = $('dd.chapters', this).text();
var done = chapters.split('/');
if ( done[0] == 1 && done[1] == 1 ) {
$(this).css('display', 'none');
}
else {
var words = $('dd.words', this).text();
words = words.replace(',', '');
words = parseInt(words, 10);
if ( words > 2000 )
words = Math.round(words / 1000) + 'K';
var title = $('h4.heading', this).html();
title = title.replace(/(\r\n|\n|\r)/gm, ' ');
title = title.replace('<!-- do not cache -->', '');
title = title.replace('href="/works', 'href="http://archiveofourown.org/works');
title = title.replace('href="/users', 'href="http://archiveofourown.org/users');
var rating = $('ul.required-tags .rating .text', this).text();
if (rating == 'Teen And Up Audiences')
rating = 'T';
if (rating == 'General Audiences')
rating = 'G';
if (rating == 'Mature')
rating = 'M';
if (rating == 'Explicit')
rating = 'E';
if (rating == 'Not Rated')
rating = 'NR';
var summary = $('blockquote.summary', this).html();
var fic_status = '';
var chapters = $('dd.chapters', this).text();
var done = chapters.split('/');
if ( done[0] !== done[1] )
fic_status = ' WIP';
var title_line = '<p>' + title + '(' + rating + ', ' + words + fic_status + ')' + '</p>';
var summary_line = '<blockquote>' + summary + '</blockquote>';
var textarea_select = '<textarea id="clipboard-textarea'+ index +'">' + title_line + summary_line + '</textarea>';
var button = '<button class="clipboard-btn" id="clipboard-'+ index +'">+</button>';
$('blockquote.summary', this).append(textarea_select);
$('p.datetime', this).append(button);
}
});
$(".clipboard-btn").click(function(e) {
var index = $(this).attr('id');
var textarea_id = index.replace('clipboard-', '');
//console.log( 'Textarea ID: #clipboard-textarea' + textarea_id);
var target = $('#clipboard-textarea'+ textarea_id);
target.css('background-color', '#ffc');
target.focus();
target.select();
document.execCommand("Copy", false, null);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment