-
Notifications
You must be signed in to change notification settings - Fork 5
/
duo-comment-links.user.js
36 lines (32 loc) · 1.3 KB
/
duo-comment-links.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// ==UserScript==
// @name Duolingo Comment Links
// @description Turn comment timestamps into direct links
// @match *://www.duolingo.com/*
// @author HodofHod
// @namespace HodofHod
// @version 0.0.3
// ==/UserScript==
/*
Copyright (c) 2013-2014 HodofHod (https://github.com/HodofHod)
Licensed under the MIT License (MIT)
Full text of the license is available at https://raw2.github.com/HodofHod/Userscripts/master/LICENSE
*/
function inject(f) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.setAttribute('name', 'comment_links');
script.textContent = '(' + f.toString() + ')()';
document.body.appendChild(script);
}
inject(function(){
$(document).on('mouseover', '.discussion-comments-list:not(.dlinked)', function (){
$(this).addClass('dlinked');
$('li[id*=comment-] .body').each(function(){
var $timestamp = $(this).next('.footer').contents().filter(function(){return this.nodeType === 3;}),
$link = $('<a href="' + document.location.pathname.replace(/\$.+$/, '') +
'$comment_id=' + this.id.replace(/^body-(\d+)$/, '$1') +
'">' + $timestamp.text() + '</a>');
$timestamp.replaceWith($link);
});
});
});