Guest User

Untitled

a guest
Sep 21st, 2011
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          newz.dk Enhancement Suite
  3. // @namespace     http://www.example.com/gmscripts dunno skiftes
  4. // @description   newz.dk er nu endnu mere perfekt!
  5. // @include       http://newz.dk/*
  6. // @include       http://*.newz.dk/*
  7. // @require       jQuery
  8. // @version       0.1
  9. // ==/UserScript==
  10.  
  11. function init() {
  12.     content = '<div style="font-size: 12pt"><input type="checkbox" id="kage" name="kage"><label for="kage"> test</label></div>';
  13.    
  14.     $(content).insertAfter('#nmTopBar');
  15.  
  16.     //if $.Storage.get("ajaxPageChange")
  17.         ajaxPageChange();
  18. }
  19.  
  20. function ajaxPageChange() {
  21.     // Indsætter en loading.gif
  22.     // Forsvinder efter første fAJAX, da den ikke er .live (jeg retter det senere)
  23.     content = '<div class="loading" style="float: left; margin: -2px 10px; padding: 5px; position: relative; width: 330px;"><p><img src="http://d9projects.com/loading.gif" /> Weeeeeeeeee.</p></div>';
  24.     $(content).insertAfter('.pagination');
  25.     $(".loading").ajaxStart(function(){
  26.         $('.pagination').hide();
  27.         $(this).show();
  28.     }).ajaxStop(function(){
  29.         $(this).hide();
  30.         $('.pagination').show();
  31.     }).hide();
  32.    
  33.     $('.pagination a').live('click', function(){
  34.         $.ajax({
  35.             url: $(this).attr('href'),
  36.             success: function (data) {
  37.                 //window.testa = data; // debug
  38.                
  39.                 // Henter title (side og titel på tråd), som indsættes i <title> og <h1>
  40.                 // newz.dk sætter normalt kun side ind i <h1>, når man skifter side, tsk tsk
  41.                 re = /<title>(.+)&raquo;.+&raquo;.+<\/title>/;
  42.                 a = re.exec(data)[1];
  43.                 $("#container div h1").html(a);
  44.                 $("title").html(a);
  45.                 $("#postcontainer").html($(data).find("#postcontainer").html());
  46.                
  47.                 // Sætter hash til første indlæg, så man kan kopiere link til den rette side
  48.                 window.location.hash = $("#comments > div:first-child h2 a:first-child").attr('name');
  49.                
  50.                 // Opdaterer newz.dk's variable, så den kun henter nye indlæg, når man er på sidste side
  51.                 re = /_pageId = (\d+);/;
  52.                 _pageId = parseInt(re.exec(data)[1]);
  53.                 re = /_lastPage = (\d+);/;
  54.                 _lastPage = parseInt(re.exec(data)[1]);
  55.                 if (_pageId != _lastPage)
  56.                     PauseAutoUpdate()
  57.                 else
  58.                     StartAutoUpdate();
  59.                
  60.                 // (Gen)aktiverer js for "Yderligere information", etc. ved at sætte event handlers igen (newz.dk-funktion)
  61.                 UpdatePosts();
  62.                
  63.                 // Sætter event handles for de nye knapper -- lige meget med .live
  64.                 //ajaxPageChange();
  65.             }
  66.         });
  67.         return false;
  68.     });
  69. }
  70.  
  71. init();
Advertisement
Add Comment
Please, Sign In to add comment