Created
June 13, 2016 16:25
-
-
Save suneo3476/0de2ee3ed3c2849b0595e4223731c099 to your computer and use it in GitHub Desktop.
使い方 ①CS演習の「2016年度1年生のページ」を開く ②F12又は「Ctrl+Shift+J」で開発用タブを開く ③「コンソール」「console」みたいなタブを開く ④アンカーが点滅している場所に、以下のスクリプトを step1 step2 の順にコピペしてエンター ⑤リストっぽいものが表示されたら開発用タブを「×」ですぐ閉じる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//step1 | |
(ScriptRunner=function(v){var i,n,l,p,c={},w=window,t=setTimeout;for(i=0,n=v.length;i<n;++i){l=v[i];if(typeof l=='string'||l instanceof String){l={'':l}}for(p in l){if(p){if(w[p]){continue}c[p]=1}(function(j){var s=document.createElement('script');s.type='text/javascript';s.charset='UTF-8';s.src=j;t(function(){document.documentElement.appendChild(s)},0)})(l[p])}}return function(f){if(f){t(function(){for(p in c){if(!w[p]){return t(arguments.callee,99)}}f()},0)}return arguments.callee}}) | |
([ | |
//Javascript内で外部ライブラリを呼び出すための指定 | |
{jQuery: 'https://code.jquery.com/jquery-2.2.4.min.js'}, | |
{vue: 'https://cdn.jsdelivr.net/vue/1.0.24/vue.min.js'} | |
]) | |
//step2 | |
(function(){ | |
$(document).ready(function(){ | |
//学科色(うらやましい) | |
var css = ["#4A3C94","#BF3559","#4DAB38"]; | |
//もくじリストを入れる要素を作っておく | |
$("h1:last").after("<h2>もくじリスト</h2><ul id='header_list'></ul>"); | |
//学籍番号の入ったセルをそれぞれ見る | |
$("td").each(function(){ | |
var description = "", | |
$td = $(this), | |
$a = $td.children("a"); | |
//セル内のリンクから各ページのhtmlファイルを取ってくる | |
$.ajax({ | |
url: $a.attr("href"), | |
type: 'GET', | |
dataType: 'html', | |
}) | |
.done(function(data) { | |
//取ってきたhtmlのうちh1~h6タグをそれぞれ見る | |
$(data).find( "h1,h2,h3,h4,h5,h6" ).each(function(){ | |
//h1~h6のテキストを連結する | |
description += " - " + $(this).text(); | |
}); | |
//学籍番号から学科を知る | |
var gakka = $td.children("a").text()[5]; | |
//もくじリストにひとりぶんのデータを追加する | |
//if(description.length!=0) //この行のコメントを外すと、h1~h6を書いている人しか追加されないようになる | |
$("#header_list").append("<li>"+$td.html()+" <span style='color:white;font-weight:bold;background:"+css[gakka]+"'>"+description+"</span></li>") | |
}) | |
.fail(function(data) { | |
}); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment