Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Detect new comments on Hashtable's blog
- // @namespace http://h16free.pltplp.net/
- // @version 0.1
- // @description enter something useful
- // @match http://h16free.com/*
- // @copyright 2013, Etienne Bernard
- // ==/UserScript==
- // a function that loads jQuery and calls a callback function when jQuery has finished loading
- function addJQuery(callback) {
- var script = document.createElement("script");
- script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");
- script.addEventListener('load', function() {
- var script = document.createElement("script");
- script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
- document.body.appendChild(script);
- }, false);
- document.body.appendChild(script);
- }
- // the guts of this userscript
- function main() {
- var cookies;
- var readCookie = function(name,c,C,i){
- if(cookies){ return cookies[name]; }
- c = document.cookie.split('; ');
- cookies = {};
- for(i=c.length-1; i>=0; i--){
- C = c[i].split('=');
- cookies[C[0]] = C[1];
- }
- return cookies[name];
- }
- var articleId = jQ('article.entry-plain').attr('id');
- if (articleId) {
- articleId = articleId.substr(5);
- var cookieName = 'post' + articleId;
- // Check if we have a cookie for this article
- var cookie = readCookie(cookieName);
- if (cookie !== undefined) {
- var lastViewed = parseInt(cookie, 10);
- jQ('article.comment-block > header > a > time').each(function() {
- var t = new Date(jQ(this).attr('datetime'))
- t = t.getTime() - 7200000; // Fix timezone
- if (t > lastViewed) {
- jQ(this).parents('article').parent('li').css('outline', '2px dotted red');
- }
- });
- }
- document.cookie = cookieName + '=' + (new Date().getTime()) + ';path=/;expires=Tue, 31 Dec 2019 23:00:00 GMT';
- }
- }
- // load jQuery and execute the main function
- addJQuery(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement