Advertisement
Guest User

h16

a guest
May 22nd, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name       Detect new comments on Hashtable's blog
  3. // @namespace  http://h16free.pltplp.net/
  4. // @version    0.1
  5. // @description  enter something useful
  6. // @match      http://h16free.com/*
  7. // @copyright  2013, Etienne Bernard
  8. // ==/UserScript==
  9.  
  10. // a function that loads jQuery and calls a callback function when jQuery has finished loading
  11. function addJQuery(callback) {
  12.     var script = document.createElement("script");
  13.     script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");
  14.     script.addEventListener('load', function() {
  15.         var script = document.createElement("script");
  16.         script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  17.         document.body.appendChild(script);
  18.     }, false);
  19.     document.body.appendChild(script);
  20. }
  21.  
  22. // the guts of this userscript
  23. function main() {
  24.    
  25.     var cookies;
  26.     var readCookie = function(name,c,C,i){
  27.         if(cookies){ return cookies[name]; }
  28.         c = document.cookie.split('; ');
  29.         cookies = {};
  30.         for(i=c.length-1; i>=0; i--){
  31.             C = c[i].split('=');
  32.             cookies[C[0]] = C[1];
  33.         }
  34.         return cookies[name];
  35.     }
  36.    
  37.     var articleId = jQ('article.entry-plain').attr('id');
  38.     if (articleId) {
  39.         articleId = articleId.substr(5);
  40.         var cookieName = 'post' + articleId;
  41.         // Check if we have a cookie for this article
  42.         var cookie = readCookie(cookieName);
  43.         if (cookie !== undefined) {
  44.             var lastViewed = parseInt(cookie, 10);
  45.             jQ('article.comment-block > header > a > time').each(function() {
  46.                 var t = new Date(jQ(this).attr('datetime'))
  47.                 t = t.getTime() - 7200000; // Fix timezone
  48.                 if (t > lastViewed) {
  49.                     jQ(this).parents('article').parent('li').css('outline', '2px dotted red');
  50.                 }
  51.             });
  52.         }
  53.         document.cookie = cookieName + '=' + (new Date().getTime()) + ';path=/;expires=Tue, 31 Dec 2019 23:00:00 GMT';
  54.     }
  55. }
  56.  
  57. // load jQuery and execute the main function
  58. addJQuery(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement