Scripts:Animepage:Sourcecode2: Difference between revisions
Jump to navigation
Jump to search
(v1 of lupin III) |
m (Firefox Script:Sourcecode2 moved to Scripts:Animepage:Sourcecode2) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<pre> | |||
// AniDB-Site-Enhancements: Mass Select | |||
// - Select all files of a group | |||
// | |||
// Version 20051210.01 | |||
// works with FF1.5 and greasemonkey 0.6.4 | |||
// Copyright (c) 2005, Lupin III. | |||
// Released under the GPL license | |||
// http://www.gnu.org/copyleft/gpl.html | |||
// | |||
// Thanks to | |||
// TechNiko for the webspace | |||
// visnu for some advice on speedups for long animelists | |||
// | |||
// ==UserScript== | // ==UserScript== | ||
// @name | // @name AniDB-Site-Enhancer: Mass Select | ||
// @namespace | // @namespace lupin_sanseis_scripts | ||
// @description | // @description selects all files of a release group, replaces vote dropdowns with textfields | ||
// @include http://anidb.info/* | // @include http://anidb.info/perl-bin/animedb.pl?show=anime&* | ||
// ==/UserScript== | // ==/UserScript== | ||
Line 9: | Line 23: | ||
// 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 | checkbox_names = new Object(); | ||
function initialize() { | function initialize() { | ||
// use '//' to disable unwanted functions | |||
group_selects(); | |||
} | |||
function group_selects () { | |||
// look up the grouplist table (using the bold "Group Info:" as an anchor, as it's fast to find) | |||
var group_table = document.evaluate("//b/text()[starts-with(.,'Group') and contains(., 'Info:')]/../../../..", document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; | |||
if (group_table == null){ | |||
return; | |||
} | |||
// search for trs of the group-list-table | |||
// | var trs = document.evaluate(".//tr", group_table, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | ||
var regexp = /gid=(\d+)"/; | |||
// walk through all rows of the table | |||
for (var i=0; i < trs.snapshotLength; i++) { | |||
if (match) { | var tr = trs.snapshotItem(i); | ||
// found the | // create an adittional column to add to the end of the row | ||
var | var td = document.createElement("td"); | ||
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(); | |||
var input = document.createElement('input'); | |||
input.setAttribute('type', 'checkbox'); | |||
input.setAttribute('id', 'toggle_gid_'+gid); | |||
input.setAttribute('value', gid); | |||
input.addEventListener('click', toggle, false); | |||
td.appendChild(input); | |||
} else | |||
if (tr.innerHTML.match(/Group Info:/i)) { | |||
td.setAttribute('bgcolor', '#b0b0b0'); | |||
td.appendChild(document.createTextNode('toggle all')); | |||
} | } | ||
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 | ||
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 | ||
// if the checkboxname is like madd.f.xyz, try to find the gid in the same table-row | |||
// and add the checkboxname to the corresponding array | |||
var checkboxes = document.evaluate("//input[@type='checkbox' and starts-with(@name, 'madd.f.')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |||
var regexp = /gid=(\d+)/; | |||
for (var i=0; i < checkboxes.snapshotLength; i++) { | |||
var tr = checkboxes.snapshotItem(i).parentNode.parentNode; | |||
if (match = regexp.exec(tr.innerHTML)) { | |||
var gid = match[1]; | |||
if (checkbox_names[gid]) { | |||
checkbox_names[gid].push(checkboxes.snapshotItem(i).name); | |||
} | } | ||
} | } | ||
Line 81: | Line 89: | ||
// add a title attribute to the created checkboxes | // add a title attribute to the created checkboxes | ||
for (var | for (var gid in checkbox_names) { | ||
document.getElementById('toggle_gid_'+ | document.getElementById('toggle_gid_'+gid).setAttribute('title', 'Toggle all files of this anime-group ('+checkbox_names[gid].length+' files)'); | ||
document.getElementById('toggle_gid_'+ | 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 < | var as = document.evaluate("//a[contains(@href, 'expandall') and .//*[contains(@title, 'all entries')]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | ||
for (var i=0; i < as.snapshotLength; i++) { | |||
as.snapshotItem(i).href += '&showallag=1'; | |||
} | } | ||
// finally add the function for the checkbox onclick-handler to the document | // finally add the function for the checkbox onclick-handler to the document | ||
function toggle(_gid) { | |||
var _gid = this.getAttribute('value'); | |||
function toggle(_gid) { | |||
for (var i=0; i < checkbox_names[_gid].length; i++) { | |||
document.getElementsByName(checkbox_names[_gid][i])[0].checked = document.getElementById('toggle_gid_'+_gid).checked; | |||
} | |||
if (document.getElementById('toggle_gid_'+_gid).checked) { | |||
alert('Selected ' + checkbox_names[_gid].length + ' files. Please check for correctness!'); | |||
} else { | |||
alert('Removed all checkmarks for this group!'); | |||
} | |||
} | |||
} | } | ||
window.addEventListener("load", initialize(), false); | window.addEventListener("load", initialize(), false); | ||
})(); | })(); </pre> |
Latest revision as of 16:15, 23 July 2006
// AniDB-Site-Enhancements: Mass Select // - Select all files of a group // // Version 20051210.01 // works with FF1.5 and greasemonkey 0.6.4 // Copyright (c) 2005, Lupin III. // Released under the GPL license // http://www.gnu.org/copyleft/gpl.html // // Thanks to // TechNiko for the webspace // visnu for some advice on speedups for long animelists // // ==UserScript== // @name AniDB-Site-Enhancer: Mass Select // @namespace lupin_sanseis_scripts // @description selects all files of a release group, replaces vote dropdowns with textfields // @include http://anidb.info/perl-bin/animedb.pl?show=anime&* // ==/UserScript== (function() { // 2D-array containing all the checkbox names corresponding to a group checkbox_names = new Object(); function initialize() { // use '//' to disable unwanted functions group_selects(); } function group_selects () { // look up the grouplist table (using the bold "Group Info:" as an anchor, as it's fast to find) var group_table = document.evaluate("//b/text()[starts-with(.,'Group') and contains(., 'Info:')]/../../../..", document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue; if (group_table == null){ return; } // search for trs of the group-list-table var trs = document.evaluate(".//tr", group_table, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var regexp = /gid=(\d+)"/; // walk through all rows of the table for (var i=0; i < trs.snapshotLength; i++) { var tr = trs.snapshotItem(i); // create an adittional column to add to the end of the row var td = document.createElement("td"); 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(); var input = document.createElement('input'); input.setAttribute('type', 'checkbox'); input.setAttribute('id', 'toggle_gid_'+gid); input.setAttribute('value', gid); input.addEventListener('click', toggle, false); td.appendChild(input); } else if (tr.innerHTML.match(/Group Info:/i)) { td.setAttribute('bgcolor', '#b0b0b0'); td.appendChild(document.createTextNode('toggle all')); } tr.appendChild(td); } // if checkbox_names still contains no elements, it's no animelisting --> exit function var found = false; for (var gid in checkbox_names) { found = true; break; } if (!found) { return; } // walk through all checkboxes in the page // if the checkboxname is like madd.f.xyz, try to find the gid in the same table-row // and add the checkboxname to the corresponding array var checkboxes = document.evaluate("//input[@type='checkbox' and starts-with(@name, 'madd.f.')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var regexp = /gid=(\d+)/; for (var i=0; i < checkboxes.snapshotLength; i++) { var tr = checkboxes.snapshotItem(i).parentNode.parentNode; if (match = regexp.exec(tr.innerHTML)) { var gid = match[1]; if (checkbox_names[gid]) { checkbox_names[gid].push(checkboxes.snapshotItem(i).name); } } } // add a title attribute to the created checkboxes for (var gid in checkbox_names) { document.getElementById('toggle_gid_'+gid).setAttribute('title', 'Toggle all files of this anime-group ('+checkbox_names[gid].length+' files)'); 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) var as = document.evaluate("//a[contains(@href, 'expandall') and .//*[contains(@title, 'all entries')]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (var i=0; i < as.snapshotLength; i++) { as.snapshotItem(i).href += '&showallag=1'; } // finally add the function for the checkbox onclick-handler to the document function toggle(_gid) { var _gid = this.getAttribute('value'); for (var i=0; i < checkbox_names[_gid].length; i++) { document.getElementsByName(checkbox_names[_gid][i])[0].checked = document.getElementById('toggle_gid_'+_gid).checked; } if (document.getElementById('toggle_gid_'+_gid).checked) { alert('Selected ' + checkbox_names[_gid].length + ' files. Please check for correctness!'); } else { alert('Removed all checkmarks for this group!'); } } } window.addEventListener("load", initialize(), false); })();