Scripts:Animepage:Sourcecode2: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
No edit summary
Line 1: Line 1:
<pre>
<pre>
// AniDB-Site-Enhancer-Mass-Select
// - Select all files of a group
//
// Version 20050809.02
// Copyright (c) 2005, Lupin III.
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
//
// ==UserScript==
// ==UserScript==
// @name          select_all_of_a_group
// @name          AniDB-Site-Enhancer-Mass-Select
// @namespace     lupin_sanseis_scripts
// @namespace   lupin_sanseis_scripts
// @description   selects all files of a release group
// @description selects all files of a release group
// @include        http://anidb.info/*
// @include        http://anidb.info/perl-bin/animedb.pl?show=anime*
// ==/UserScript==
// ==/UserScript==


Line 10: Line 19:


   // 2D-array containing all the checkbox names corresponding to a group
   // 2D-array containing all the checkbox names corresponding to a group
   checkbox_names = new Array();
   checkbox_names = new Object();


   function initialize() {
   function initialize() {
      group_selects();
  }


      var gids = new Array();
  function group_selects () {
       // walk through all tbodies (they are created by the browser DOM internally, they don't have to be in source)
       // search for trs of the group-list-table
       for (var i=0; i < document.getElementsByTagName("tbody").length; i++) {
       var trs = document.evaluate("//tr[not(.//table) and ..//text()[contains(., 'Group')] and ..//text()[contains(., 'Info:')]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        var tbody = document.getElementsByTagName("tbody")[i];


        // the group-listing-table contains no inner table, so it's the wrong tbody if a table is found inside
      var regexp = /gid=(\d+)"/;
        match = tbody.innerHTML.match(/table/i);
        if (match) { continue; }


        // search for "Group Info"
      // walk through all rows of the table
         match = tbody.innerHTML.match(/Group&nbsp;Info:/i);
      for (var i=0; i < trs.snapshotLength; i++) {
         if (match) {
         var tr = trs.snapshotItem(i);
             // found the right table
        // create an adittional column to add to the end of the row
             var regexp = /gid=(\d+)"/;
        var td = document.createElement("td");
             var tr = tbody.firstChild;
         if (match = regexp.exec(tr.innerHTML)) {
             // found a group-id, so create the subarray for the checkboxnames and the checkbox
             var gid = match[1];
             checkbox_names[gid] = new Array();


             // walk through all rows of the table
             var input = document.createElement('input');
            while (tr.nextSibling) {
            input.setAttribute('type', 'checkbox');
              if (tr.nodeType == 1
            input.setAttribute('id', 'toggle_gid_'+gid);
                && tr.nodeName == 'TR')
            input.setAttribute('onclick', 'toggle('+gid+')');
              {
            td.appendChild(input);
                  // create an adittional column to add to the end of the row
        } else
                  var td = document.createElement("td");
        if (tr.innerHTML.match(/Group&nbsp;Info:/i)) {
                  if (match = regexp.exec(tr.innerHTML)) {
            td.setAttribute('bgcolor', '#b0b0b0');
                    // found a group-id, so create the subarray for the checkboxnames and the checkbox
            td.appendChild(document.createTextNode('toggle all'));
                    var gid = match[1];
                    gids.push(gid);
                    checkbox_names[gid] = new Array();
                    var input = document.createElement('input');
                    input.setAttribute('type', 'checkbox');
                    input.setAttribute('id', 'toggle_gid_'+gid);
                    input.setAttribute('onclick', 'toggle('+gid+')');
                    td.appendChild(input);
                  } else
                  if (tr.innerHTML.match(/Group&nbsp;Info:/i)) {
                    td.setAttribute('bgcolor', '#b0b0b0');
                    td.appendChild(document.createTextNode('toggle all'));
                  }
                  tr.appendChild(td);
              }
              tr = tr.nextSibling;
            }
         }
         }
        tr.appendChild(td);
       }
       }


       // if checkbox_names still contains no elements, it's no animelisting --> exit function
       // if checkbox_names still contains no elements, it's no animelisting --> exit function
       if (checkbox_names.length == 0) { return; }
       var found = false;
      for (var gid in checkbox_names) { found = true; break; }
      if (!found) { return; }


       // walk through all checkboxes in the page
       // walk through all checkboxes in the page
       for (var i=0; i < document.getElementsByTagName("input").length; i++) {
       // if the checkboxname is like madd.f.xyz, try to find the gid in the same table-row
        var input = document.getElementsByTagName("input")[i];
      // and add the checkboxname to the corresponding array
        if (input.type == 'checkbox'
      var checkboxes = document.evaluate("//input[@type='checkbox' and starts-with(@name, 'madd.f.')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
          && input.name.search(/^madd\.f\.\d+$/) != -1) {
      var regexp = /gid=(\d+)/;
            var regexp = /gid=(\d+)/;
      for (var i=0; i < checkboxes.snapshotLength; i++) {
 
        var tr = checkboxes.snapshotItem(i).parentNode.parentNode;
            // if the checkboxname is like madd.f.xyz, try to find the gid in the same table-row
        if (match = regexp.exec(tr.innerHTML)) {
            // and add the checkboxname to the corresponding array
            var gid = match[1];
            var tr = input.parentNode.parentNode;
            if (checkbox_names[gid]) {
            if (match = regexp.exec(tr.innerHTML)) {
              checkbox_names[gid].push(checkboxes.snapshotItem(i).name);
              var gid = match[1];
              if (checkbox_names[gid]) {
                  checkbox_names[gid].push(input.name);
              }
             }
             }
         }
         }
Line 82: Line 75:


       // add a title attribute to the created checkboxes
       // add a title attribute to the created checkboxes
       for (var i=0; i < gids.length; i++) {
       for (var gid in checkbox_names) {
         document.getElementById('toggle_gid_'+gids[i]).setAttribute('title', 'Toggle all files of this anime-group ('+checkbox_names[gids[i]].length+' files)');
         document.getElementById('toggle_gid_'+gid).setAttribute('title', 'Toggle all files of this anime-group ('+checkbox_names[gid].length+' files)');
         document.getElementById('toggle_gid_'+gids[i]).parentNode.appendChild(document.createTextNode('('+checkbox_names[gids[i]].length+')'));
         document.getElementById('toggle_gid_'+gid).parentNode.appendChild(document.createTextNode('('+checkbox_names[gid].length+')'));
       }
       }


       // expand the grouplist too when expanding all file-entries (change href of plus icon)
       // expand the grouplist too when expanding all file-entries (change href of plus icon)
       for (var i=0; i < document.getElementsByTagName("a").length; i++) {
      var as = document.evaluate("//a[contains(@href, 'expandall') and .//*[contains(@title, 'all entries')]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
         var a = document.getElementsByTagName("a")[i];
       for (var i=0; i < as.snapshotLength; i++) {
        if (a.href.match(/expandall/)
         as.snapshotItem(i).href += '&showallag=1';
          && a.innerHTML.match(/all entries/)) {
            a.href += '&showallag=1';
            break;
        }
       }
       }


       // finally add the function for the checkbox onclick-handler to the document
       // finally add the function for the checkbox onclick-handler to the document
       // has to be done this way, because of scoping of function names
       window.toggle =
      var script = document.createElement('script');
       function(_gid) {
      script.type = 'text/javascript';
         for (var i=0; i < checkbox_names[_gid].length; i++) {
      script.appendChild(document.createTextNode("\
             document.getElementsByName(checkbox_names[_gid][i])[0].checked = document.getElementById('toggle_gid_'+_gid).checked;
       function toggle(_gid) {\
         }
         for (var i=0; i < checkbox_names[_gid].length; i++) {\
         if (document.getElementById('toggle_gid_'+_gid).checked) {
             document.getElementsByName(checkbox_names[_gid][i])[0].checked = document.getElementById('toggle_gid_'+_gid).checked;\
             alert('Selected ' + checkbox_names[_gid].length + ' files. Please check for correctness!');
         }\
         } else {
         if (document.getElementById('toggle_gid_'+_gid).checked) {\
             alert('Removed all checkmarks for this group!');
             alert('Selected ' + checkbox_names[_gid].length + ' files. Please check for correctness!');\
         }
         } else {\
       }
             alert('Removed all checkmarks for this group!');\
         }\
       }"));
 
      document.getElementsByTagName("head")[0].appendChild(script);
   }
   }


   window.addEventListener("load", initialize(), false);
   window.addEventListener("load", initialize(), false);


})();</pre>
})();</pre>
24

edits

Navigation menu

MediaWiki spam blocked by CleanTalk.
MediaWiki spam blocked by CleanTalk.