Created
June 8, 2016 12:23
-
-
Save suneo3476/724c8b53908572eadc6bfbcf81901967 to your computer and use it in GitHub Desktop.
使い方 ①CS演習の「2016年度1年生のページ」を開く ②F12又は「Ctrl+Shift+J」で開発用タブを開く ③「コンソール」「console」みたいなタブを開く ④アンカーが点滅している場所に、以下のスクリプトをコピペしてエンター ⑤しばらく待つとページにもくじリストが生成される
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
(ScriptRunner=function(v){var i,n,l,p,s,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}s=document.createElement('script');s.type='text/javascript';s.charset='UTF-8';s.src=l[p];document.documentElement.appendChild(s)}}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'}, | |
{$: 'https://code.jquery.com/jquery-2.2.4.min.js'}, | |
{vue: 'https://cdn.jsdelivr.net/vue/1.0.24/vue.min.js'} | |
]) | |
(function(){ | |
$(document).ready(function(){ | |
//学科色(うらやましい) | |
var css = ["#4A3C94","#BF3559","#4DAB38"]; | |
//もくじリストを入れる要素を作っておく | |
$("h1:last").after("<h2>もくじリスト</h2><ul id='header_list'></ul>"); | |
//検索フォームを作るつもりだった | |
// $("#header_list").append("<form><input type='text'></form>"); | |
//学籍番号の入ったセルをそれぞれ見る | |
$("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]; | |
//もくじリストにひとりぶんのデータを追加する | |
$("#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