一段删除表格特定列的js脚本,可应用于Hyperpolyglot

     0评论

Hyperpolyglot是一个不错的站点,提供了多种编程语言从基本语法到常用函数等的比较表格,有的页面上的表格列比较多,屏幕比较窄时看起来费力,有些列也确实不是自己关注的。本文提供的这个脚本可以帮你删除特定的列,只保留那些你关心的。

以下脚本已发布于gist,欢迎star、comment。

需要注意的是,其中正则使用了dotAll修饰符s,只有比较新的浏览器才支持,旧浏览器可以尝试将.*?换成[\s\S]*?

// By qiushan // Mainpage: https://vps123.top // 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(/(.*?)$1"; p = new RegExp(find, "gis"); table_html = table_html.replace(p, ""); } table_ele.innerHTML = table_html;

实验页面:Scripting Languages I: Node.js, Python, PHP, Ruby

以下是运行脚本前后的比较图:

运行脚本前

屏幕太窄,显示不全,囧……

运行脚本后

现在好多了,专心于python和php。

-- EOF --

本文最后修改于5年前 (2019-05-06)

差评不太行一般挺好非常不错 (No Ratings Yet)
读取中...
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址