Benutzer:Lustiger seth/list2table.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/*
task: replace lists with tables in watchlist/contribs and some other logs
tested in firefox only
*/
$(function (){
function re_cat(arr){
return new RegExp(arr.map(
function(r){
return r.source
}
).join(''));
}
function get_list_patterns(){
const patterns = {
'classes': {
'plainlinks': {
name: "abuselog",
show_sections: false,
re: re_cat([
/^([0-9T:-]+):\s*/, // date
/(<a .*?<\/a>)\s*/, // user
/(<span .*?<\/span>) triggered /, // user
/(<a .*?<\/a>), /, // rule
/performing the action "([^"]+)" /, // action
/on (<a .*?<\/a>)\.\s*/, // page
/Actions taken: ([^;]+);\s*/, // action
/Filter description: (.*)\s/, // description
/\((<a .*?<\/a>)\)\s*$/ // tools
]),
heading: ['date', 'user', 'user', 'rule', 'did', 'page', 'action', 'description', 'tools'],
format: function(cells, last_row){
cells[3] = cells[3].replace(/>talk</, '>t<').replace(/>block</, '>b<').replace(/>contribs</, '>c<').replace(/>\(\s*/, '>').replace(/>\s*\)\s*</, '><');
cells[4] = cells[4].replace(/>filter /, '>');
[2, 6, 8].forEach(i => {
if(last_row[i] === cells[i]){
cells[i] = '-"-'
}else{
last_row[i] = cells[i];
}
});
cells[9] = cells[9].replace(/>details</, '>d<').replace(/>examine</, '>e<');
}
},
/*
<li>
1: 2021-08-12T14:07:45:
2: <a href="/wiki/Spezial:Beitr%C3%A4ge/127.0.0.1" class="mw-userlink mw-anonuserlink userlink" title="Spezial:Beiträge/127.0.0.1"><bdi>127.0.0.1</bdi></a>
3: <span class="mw-usertoollinks">(
<a href="/w/index.php?title=Benutzer_Diskussion:127.0.0.1&action=edit&redlink=1" class="new mw-usertoollinks-talk userlink" title="Benutzer Diskussion:127.0.0.1 (Seite nicht vorhanden)">talk</a>
| <a href="/wiki/Spezial:Sperren/127.0.0.1" class="mw-usertoollinks-block" title="Spezial:Sperren/127.0.0.1">block</a>)
</span> triggered
4: <a href="/wiki/Spezial:Missbrauchsfilter/276" title="Spezial:Missbrauchsfilter/276">filter 276</a>,
5: performing the action "edit"
6: on <a href="/w/index.php?title=Referenzpunkt_(Koordinaten)&redirect=no&action=edit&redlink=1" class="new" title="Referenzpunkt (Koordinaten) (Seite nicht vorhanden)">Referenzpunkt (Koordinaten)</a>.
7: Actions taken: Disallow;
8: Filter description: vermutlich kein sinnvoller Artikel
9: (<a href="/wiki/Spezial:Missbrauchsfilter-Logbuch/750813" title="Spezial:Missbrauchsfilter-Logbuch/750813">details</a>
| <a href="/wiki/Spezial:Missbrauchsfilter/examine/log/750813" title="Spezial:Missbrauchsfilter/examine/log/750813">examine</a>)
</li>
*/
'mw-contributions-list': {
name: "contribs",
show_sections: false,
re: re_cat([
/^(<span .*?<\/span>)\s*/, // vis
/(<a .*?<\/a>)\s*/, // date
/(<span .*?<\/span>)\s*<span class="mw-changeslist-separator"><\/span>\s*/, // diff/hist
/(<strong .*?<\/strong>|<span .*?<\/span>)\s*?\s*<span class="mw-changeslist-separator"><\/span>\s*/, // bytes diff
/(<abbr .*?<\/abbr>|)\s*/, // flags
/(<a .*?<\/a>)\s*\s*/, // page title
/(<span .*?<\/span>)/, // summary
/(\s*<span class="mw-uctop">[^<]*<\/span>|)/, // current or not
/(\s*<span class="mw-rollback-link">.*?<\/span>|)/, // rollback
/(\s*<span class="mw-tag.*?<\/span>|)\s*$/ // tags
]),
heading: ['vis', 'date', 'diff<br />hist ', 'bytes', 'flag', 'page', 'summary', 'c', 'rb', 'tags'],
format: function(cells, last_row){
cells[1] = cells[1].replace(/>change visibility</, '>chg<');
cells[3] = cells[3].replace(/>diff</, '>d<').replace(/>hist</, '>h<');
cells[6] = cells[6].replace(/>Benutzer(?:in|):/, '>user:').replace(/>Benutzer(?:in|) Diskussion:/, '>user talk:').replace(/>Wikipedia:/, '>WP:');
cells[8] = cells[8].replace(/>current/, '>c');
cells[9] = cells[9].replace(/>rollback /, '>').replace(/ edits?</, '<').replace(/more than /, '>');
cells[10] = cells[10].replace(/<a [^>]+>Tags<\/a>\s*:\s/, '').replace(/Mobile web edit/, 'mob.').replace(/Mobile edit/, 'mob. web');
cells[1] = cells[1].replace(/>\(\s*/, '>').replace(/>\s*\)\s*</, '><');
const css_classes = ['.comment--without-parentheses', '.mw-changeslist-links', '.mw-diff-bytes', '.mw-uctop', '.mw-rollback-link', '.mw-tag-markers'];
css_classes.forEach(c => {
document.styleSheets[0].addRule(c + '::before','content: "";')
document.styleSheets[0].addRule(c + '::after','content: "";')
});
}
},
/*
<li data-mw-revid="214754025" class="mw-contributions-current">
1: <span class="mw-revdelundel-link">
(<a href="/w/index.php?title=Spezial:Versionsl%C3%B6schung&type=revision&target=Wikipedia%3ABearbeitungsfilter%2Flatest_topics&ids=214754025" title="Spezial:Versionslöschung">change visibility</a>)
</span>
2: <a href="/w/index.php?title=Wikipedia:Bearbeitungsfilter/latest_topics&oldid=214754025" class="mw-changeslist-date" title="Wikipedia:Bearbeitungsfilter/latest topics">2021-08-14T11:37:42</a>
3: <span class="mw-changeslist-links">
span><a href="/w/index.php?title=Wikipedia:Bearbeitungsfilter/latest_topics&diff=prev&oldid=214754025" class="mw-changeslist-diff" title="Wikipedia:Bearbeitungsfilter/latest topics">diff</a></span>
<span><a href="/w/index.php?title=Wikipedia:Bearbeitungsfilter/latest_topics&action=history" class="mw-changeslist-history" title="Wikipedia:Bearbeitungsfilter/latest topics">hist</a></span>
</span>
<span class="mw-changeslist-separator"></span>
4: <span dir="ltr" class="mw-plusminus-pos mw-diff-bytes" title="9,369 bytes after change">+4</span>
<span class="mw-changeslist-separator"></span>
5: <abbr class="minoredit" title="This is a minor edit">m</abbr>
6: <a href="/wiki/Wikipedia:Bearbeitungsfilter/latest_topics" class="mw-contributions-title" title="Wikipedia:Bearbeitungsfilter/latest topics">Wikipedia:Bearbeitungsfilter/latest topics</a>
7: <span class="comment comment--without-parentheses">Bot: (#276): vermutlich kein sinnvoller Artikel</span>
8opt: <span class="mw-uctop">current</span>
9opt: <span class="mw-rollback-link">
<a href="/w/index.php?title=Wikipedia:Bearbeitungsfilter/latest_topics&action=rollback&from=CamelBot&token=deadbeaf%2B%5C" title=""Rollback" reverts the last contributor's edit(s) to this page in one click" data-mw="interface">
rollback more than 10 edits
</a>
</span>
</li>
*/
'special': {
name: "watchlist",
show_sections: true,
re: re_cat([
/(<a .*?<\/a>|\bdiff\b).*?/, // diff
/(<a .*?<\/a>).*?/, // hist
/(<a .*?<\/a>).*?/, // page
/(<span class="mw-changeslist-date[^"]*">[0-9:]+<\/span>).*?/, // timestamp
/(<strong .*?<\/strong>|<span dir="ltr" class="mw-plusminus-[a-z]+ mw-diff-bytes" .*?<\/span>).*?/, // bytes diff
/(<a .*?<\/a>)\s*/, // user
/(<span class="mw-usertoollinks mw-changeslist-links">.*<\/span>)\s*/, // user tools
/(\s*<span .*<\/span>|\Z)/ // summary, tags
]),
heading: ['diff', 'hist', 'page', 'time', 'bytes', 'user', 'u. links', 'summary', 'tags'],
format: function(cells, last_row){
cells[7] = cells[7].replace(/>talk</, '>t<').replace(/>contribs</, '>c<').replace(/>block</, '>b<');
cells[8] = cells[8].replace(/^\s*/, '').replace(/<span class="mw-rollback-link">.*/, '');
const tags = /(<span class="mw-tag-markers">.*)/.exec(cells[8]);
if(tags){
cells[9] = tags[1];
cells[8] = cells[8].replace(/<span class="mw-tag-markers">.*/, '');
}else{
cells[9] = '';
}
cells[9] = cells[9].replace(/<a .*?>Tags?<\/a>:\s*/, '');
const css_classes = ['.comment--without-parentheses', '.mw-changeslist-links', '.mw-diff-bytes', '.mw-uctop']; // '.mw-tag-markers'
css_classes.forEach(c => {
document.styleSheets[0].addRule(c + '::before','content: "";')
document.styleSheets[0].addRule(c + '::after','content: "";')
});
}
}
/*
<div class="mw-rcfilters-ui-highlights">
<div class="mw-rcfilters-ui-highlights-color-none" data-color="none"></div>
<div class="mw-rcfilters-ui-highlights-color-c1" data-color="c1"></div>
<div class="mw-rcfilters-ui-highlights-color-c2" data-color="c2"></div>
<div class="mw-rcfilters-ui-highlights-color-c3" data-color="c3"></div>
<div class="mw-rcfilters-ui-highlights-color-c4" data-color="c4"></div>
<div class="mw-rcfilters-ui-highlights-color-c5" data-color="c5"></div>
</div>
<span class="mw-changeslist-line-inner" data-target-page="Wikipedia:Fragen zur Wikipedia">
<div class="mw-changeslist-links">
<span>
1: <a href="/w/index.php?title=Wikipedia:Fragen_zur_Wikipedia&curid=6977098&diff=214751110&oldid=214747823" class="mw-changeslist-diff" title="Wikipedia:Fragen zur Wikipedia">diff</a>
</span>
<span>
2: <a href="/w/index.php?title=Wikipedia:Fragen_zur_Wikipedia&curid=6977098&action=history" class="mw-changeslist-history" title="Wikipedia:Fragen zur Wikipedia">hist</a>
</span>
</div>
<span class="mw-changeslist-separator"></span>
<span class="mw-title">
3: <a href="/wiki/Wikipedia:Fragen_zur_Wikipedia" class="mw-changeslist-title" title="Wikipedia:Fragen zur Wikipedia">Wikipedia:Fragen zur Wikipedia</a>
</span>
<span class="mw-changeslist-separator--semicolon"></span>
4: <span class="mw-changeslist-date">09:28:29</span>
<span class="mw-changeslist-separator"></span>
5: <span dir="ltr" class="mw-plusminus-pos mw-diff-bytes" title="72,244 bytes after change">+300</span>
<span class="mw-changeslist-separator"></span>
6: <a href="/wiki/Benutzer:lustiger_seth" class="mw-userlink userlink" title="Benutzer:lustiger_seth">
<bdi>lustiger_seth</bdi>
<span class="adminMark"> (A)</span>
</a>
7: <span class="mw-usertoollinks mw-changeslist-links">
<span>
<a href="/wiki/Benutzer_Diskussion:lustiger_seth" class="mw-usertoollinks-talk userlink" title="Benutzer Diskussion:lustiger_seth">talk</a>
</span>
<span>
<a href="/wiki/Spezial:Beitr%C3%A4ge/lustiger_seth" class="mw-usertoollinks-contribs userlink" title="Spezial:Beiträge/lustiger_seth">contribs</a>
</span>
<span><a href="/wiki/Spezial:Sperren/lustiger_seth" class="mw-usertoollinks-block" title="Spezial:Sperren/lustiger_seth">block</a></span>
</span>
8opt: <span class="comment comment--without-parentheses">
<span dir="auto">
<span class="autocomment">
<a href="/wiki/Wikipedia:Fragen_zur_Wikipedia#Farbe_von_Rotlinks" title="Wikipedia:Fragen zur Wikipedia">→Farbe von Rotlinks</a>
:
</span>
Frage
</span>
</span>
9opt: <span class="mw-tag-markers">
<a href="/wiki/Spezial:Markierungen" title="Spezial:Markierungen">Tag</a>
:
<span class="mw-tag-marker mw-tag-marker-mw-manual-revert">Manual revert</span>
</span>
<span class="mw-rollback-link">
<a href="/w/index.php?title=Wikipedia:Fragen_zur_Wikipedia&action=rollback&from=lustiger+seth&token=deadbeaf%2B%5C" title=""Rollback" reverts the last contributor's edit(s) to this page in one click" data-mw="interface">rollback</a>
</span>
</span>
*/
},
'ids': {
'pagehistory': {
name: "history",
show_sections: false,
re: new RegExp([
/(<a .*?<\/a>|\b(?:cur|Aktuell)\b).*?/, // 1 cur
/(<a .*?<\/a>|\b(?:prev|Vorherige)\b).*?/, // prev
/(<input .*?>).*?/, // 2 radio button from
/(<input .*?>).*?/, // radio button to
/(<input .*?>.*?|)/, // checkbox select
/(<span class="[^"]+">\s*|)/, // date-container
/(<a href="[^"]+" class="[^"]*mw-changeslist-date[^"]*"[^>]*>(?:[0-9T:-]+|[0-9][0-9A-Za-z: ,.-]+[0-9]{4})<\/a>).*?/, // 3 date
/(<a .*?<\/a>)\s*/, // 4 user
/(<span class="mw-usertoollinks mw-changeslist-links">.*?<\/span>)\s*\s*/, // 5 user tools
/(<abbr [^>]*>m<\/abbr>|)\s*/, // 6 minor change?
/<span class="mw-changeslist-separator"><\/span>\s*/,
/<span class="history-size mw-diff-bytes" data-mw-bytes="([0-9]+)">(?:[0-9.,]+\s+[bB]ytes|empty|leer)<\/span>.*?/, // 7 size
/(<strong .*?<\/strong>|<span (?:dir="ltr" |)class="mw-plusminus-[a-z]+ mw-diff-bytes" .*?<\/span>).*?/, // 8 diff size
/(<span class="comment\b[^"]*">(?:.|\s)*?<\/span>)\s*/, // 9 comment
/(<span class="mw-changeslist-links">.*<\/span>|<span\b.*<\/span>|)$/, // 10 edit tools, tags, checked revisions
].map(function(r) {return r.source}).join('')),
heading: ['cur/prev', 'sel', 'time', 'user', 'user tools', 'm', 'size', 'diff', 'comment', 'edit tools', 'tags', 'chk'],
format: function(cells, last_row){
cells[1] = '<nobr>' + cells[1] + '/' + cells[2] + '</nobr>';
// re-activate "until" radio-buttons
cells[4] = cells[4].replace(/ disabled=""/, '');
cells[2] = '<nobr>' + cells[3] + cells[4] + cells[5] + '</nobr>';
cells.splice(3, 3);
if(cells[3].length > 0){
cells[4] = cells[3] + cells[4] + "</span>";
}
cells.splice(3, 1);
cells[5] = cells[5].replace(/>talk</, '>t<').replace(/>contribs</, '>c<').replace(/>block</, '>b<');
cells[10] = cells[10].replace(/<span class="mw-rollback-link">.*?<\/span>/, '').replace(/>updated since your last visit</, '>updated<').replace(/>undo</, '>👎<').replace(/>thank</, '>👍<');
const checked_rev = /(<span class="fr-[a-z-]+ plainlinks">.*)/.exec(cells[10]);
if(checked_rev){
cells[12] = checked_rev[1];
cells[10] = cells[10].substr(0, cells[10].length - cells[12].length);
cells[12] = cells[12].replace(/\[automatically checked\]/, 'auto').replace(/\[checked (by .*)\]/, '$1');
}else{
cells[12] = '';
}
const tags = /(<span class="mw-tag-markers">.*)/.exec(cells[10]);
if(tags){
cells[11] = tags[1];
cells[10] = cells[10].substr(0, cells[10].length - cells[11].length);
}else{
cells[11] = '';
}
cells[11] = cells[11].replace(/<a .*?>Tags?<\/a>:\s*/, '').replace(/Mobile web edit/, 'mob.').replace(/Mobile edit/, 'mob. web');
const css_classes = ['.comment--without-parentheses', '.mw-changeslist-links', '.mw-diff-bytes', '.mw-uctop', '.mw-tag-markers', '.mw-changeslist-links > span:not(:first-child)'];
css_classes.forEach(c => {
document.styleSheets[0].addRule(c + '::before','content: "";')
document.styleSheets[0].addRule(c + '::after','content: "";')
});
}
}
/*
<li data-mw-revid="12345" class="mw-tag-wikieditor selected before">
<span class="flaggedrevs-color-1">
<span class="mw-history-histlinks mw-changeslist-links">
1: <span>cur</span>
<span>
2: <a href="/w/index.php?title=Digitales_W%C3%B6rterbuch_der_deutschen_Sprache&diff=219375147&oldid=208792099" title="Difference with preceding revision">prev</a>
</span>
</span>
3: <input type="radio" value="219375147" disabled="" name="oldid" id="mw-oldid-null">
4: <input type="radio" value="219375147" checked="checked" name="diff" id="mw-diff-219375147">
5: <input name="ids[219375147]" type="checkbox" value="1">
<span class="mw-changeslist-time">18:33:50</span>
6: <a href="/w/index.php?title=Digitales_W%C3%B6rterbuch_der_deutschen_Sprache&oldid=219375147" class="mw-changeslist-date" title="Digita... Sprache">2022-01-20T18:33:50</a>
<span class="history-user">
7: <a href="/wiki/Benutzer:Boonekamp" class="mw-userlink userlink" title="Benutzer:Boonekamp"><bdi>Boonekamp</bdi></a>
8: <span class="mw-usertoollinks mw-changeslist-links">
<span>
<a href="/wiki/Benutzer_Diskussion:Boonekamp" class="mw-usertoollinks-talk userlink" title="Benutzer Diskussion:Boonekamp">talk</a>
</span>
<span>
<a href="/wiki/Spezial:Beitr%C3%A4ge/Boonekamp" class="mw-usertoollinks-contribs userlink" title="Spezial:Beiträge/Boonekamp">contribs</a>
</span>
<span>
<a href="/wiki/Spezial:Sperren/Boonekamp" class="mw-usertoollinks-block" title="Spezial:Sperren/Boonekamp">block</a>
</span>
</span>
</span>
9: <abbr class="minoredit" title="This is a minor edit">m</abbr>
<span class="mw-changeslist-separator"></span>
10: <span class="history-size mw-diff-bytes" data-mw-bytes="8192">8,192 bytes</span>
11: <span dir="ltr" class="mw-plusminus-neg mw-diff-bytes" title="8,192 bytes after change">−15</span>
<span class="mw-changeslist-separator"></span>
12: <span class="comment comment--without-parentheses">wie verweist bereits es folgt eine Auswahl</span>
13: <span class="mw-changeslist-links">
<span>
<span class="mw-rollback-link">
<a href="/w/index.php?title=Digitales_W%C3%B6rterbuch_der_deutschen_Sprache&action=rollback&from=Boonekamp&token=deadbeaf%2B%5C" title=""Rollback" reverts the last contributor's edit(s) to this page in one click" data-mw="interface">rollback 1 edit</a>
</span>
</span>
<span>
<span class="mw-history-undo">
<a href="/w/index.php?title=Digitales_W%C3%B6rterbuch_der_deutschen_Sprache&action=edit&undoafter=208792099&undo=219375147" title=""Undo" reverts this edit and opens the edit form in preview mode. It allows adding a reason in the summary.">undo</a>
</span>
</span>
<span>
<a class="mw-thanks-thank-link" href="//de.wikipedia.org/wiki/Spezial:Danke/219375147" title="Send a thank you notification to this user" data-revision-id="219375147" data-recipient-gender="male">thank</a>
</span>
</span>
</span>
14:<span class="mw-tag-markers">
<a href="/wiki/Spezial:Markierungen" title="Spezial:Markierungen">Tag</a>:
<span class="mw-tag-marker mw-tag-marker-mw-rollback">Rollback</span>
</span>
15:<span class="fr-hist-basic-auto plainlinks">[automatically checked]</span>
</li>
*/
}
};
return patterns;
}
function list_elem2row(elem, pattern, prev_row){
let converted = false;
let row = '';
if(elem.tagName === 'LI'){
const cells = pattern.re.exec(elem.innerHTML.replace(/\n/g, " "));
let flaggedrevs_class = "";
elem.classList.forEach(c => {
if(c.startsWith("flaggedrevs")){
flaggedrevs_class = c;
}
});
row += "<tr" + (flaggedrevs_class == '' ? '': ' class="' + flaggedrevs_class + '"') + ">";
if(cells){
pattern.format(cells, prev_row);
for(let i = 1; i < cells.length; ++i){
row += "<td>" + cells[i] + "</td>";
}
converted = true;
}else{
row += '<td colspan="' + pattern.heading.length + '">' + elem.innerHTML + "</td>";
}
row += "</tr>";
}
return {row: row, converted: converted};
}
function list2table(list, pattern){
if(list && list.children.length > 0){
table = '<table class="wikitable"><tr>';
pattern.heading.forEach(h => {
table += "<th>" + h + "</th>";
});
let found_something = 0;
table += "</tr>";
const prev_row = Array(list.children.length);
Array.from(list.children).forEach(elem => {
const li_elems = (elem.tagName === 'UL' ? Array.from(elem.children) : [elem]) ;
li_elems.forEach(li => {
const row = list_elem2row(li, pattern, prev_row);
if(row.converted){
++found_something;
table += row.row;
}
});
});
table += "</table>";
if(found_something > 0){
const mySpan = document.createElement("span");
mySpan.innerHTML = table;
list.parentNode.replaceChild(mySpan, list);
}
}
}
const patterns = get_list_patterns();
const classes_of_lists = Object.keys(patterns.classes);
classes_of_lists.forEach(class_name => {
const lists = document.getElementsByClassName(class_name);
if(lists && lists.length > 0){
if(patterns.classes[class_name].show_sections){
Array.from(lists).forEach(list => {
list2table(list, patterns.classes[class_name]);
});
}else{
list2table(lists.item(0).parentNode, patterns.classes[class_name]);
}
}
});
const ids_of_lists = Object.keys(patterns.ids);
ids_of_lists.forEach(id => {
const list = document.getElementById(id);
if(list){
list2table(list, patterns.ids[id]);
}
});
});