Skip to content

Instantly share code, notes, and snippets.

@void285
Last active May 6, 2019 13:40
Show Gist options
  • Save void285/f7f4d709dc0946db3d4df1a18bc6de1c to your computer and use it in GitHub Desktop.
Save void285/f7f4d709dc0946db3d4df1a18bc6de1c to your computer and use it in GitHub Desktop.
This script is applied to delete some columns of tables on http://hyperpolyglot.org/, for example [http://hyperpolyglot.org/scripting]. More detail at [https://vps123.top/script-to-delete-table-column-on-hyperpolyglot.html]
// By qiushan
// Detail page: https://vps123.top/script-to-delete-table-column-on-hyperpolyglot.html
// License: MIT
// [http://hyperpolyglot.org] is a wonderfull website which provides contrast of programming languages. Sometimes the table contains languages that you don't care about, you can use this script to delete them, just modify the $columnscnt and $delcolumns vars, and run it from the console.
// how many columns does the table have;
var columnscnt = 5;
// which columns do you what to delete;
var delcolumns = [2, 5];
var find, p, seq, i;
var table_ele = document.getElementsByClassName("wiki-content-table")[0];
var table_html = table_ele.innerHTML;
table_html = table_html.replace('/colspan="5"/g', 'colspan="3"');
for (i = 1; i < columnscnt+1; i++) {
if (i === 1) {
table_html = table_html.replace(/<tr>(.*?)<t([hd])/gis, "<tr>$1<t$2 flag=1");
table_html = table_html.replace(/flag=1 colspan/gis, "colspan");
} else {
find = "(<t[hd] flag=" + (i-1) + ")(.*?)<t([hd])";
p = new RegExp(find, "gis");
table_html = table_html.replace(p, "$1$2<t$3 flag=" + i);
}
}
for (i = 0; i < delcolumns.length; i++) {
seq = delcolumns[i];
find = "<t[hd] flag=" + seq + ".*?</t[hd]>";
p = new RegExp(find, "gis");
table_html = table_html.replace(p, "");
}
table_ele.innerHTML = table_html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment