授業情報ページを作成するscriptその2
code:download.js
var E=()=>{let t="class.admin.tus.ac.jp";if(location.host!==t)throw Error(This script can be only executed in "${t}");let e=document.getElementById("pkx02301:ch:table");if(!e)throw Error("シラバス照会window (#pkx02301:ch:table) が開かれていません");return Array.from(e.getElementsByClassName("rowStyle")).flatMap(o=>{let u=Array.from(o.getElementsByClassName("ui-widget-header")),l=Array.from(o.getElementsByClassName("ui-widget-content")),D=[];for(let i=0;i<Math.max(u.length,l.length);i++){let s={};ui&&(s.header=ui.innerText),li&&(s.content=li.innerText),D.push(s)}return D})};function a(t,e){if(e.length<t)throw new TypeError(t+" argument"+(t>1?"s":"")+" required, but only "+e.length+" present")}function d(t){a(1,arguments);let e=Object.prototype.toString.call(t);return t instanceof Date||typeof t=="object"&&e==="object Date"?new Date(t.getTime()):typeof t=="number"||e==="object Number"?new Date(t):((typeof t=="string"||e==="object String")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use parseISO to parse strings. See: https://git.io/fjule"),console.warn(new Error().stack)),new Date(NaN))}function M(t){return a(1,arguments),d(t).getDay()}function p(t){if(t===null||t===!0||t===!1)return NaN;let e=Number(t);return isNaN(e)?e:e<0?Math.ceil(e):Math.floor(e)}function g(t,e){a(2,arguments);let n=d(t),o=p(e);return isNaN(o)?new Date(NaN):(o&&n.setDate(n.getDate()+o),n)}var b=7,6,5,4,3,2,1;function A(t,e){a(2,arguments);let n=J(e);return g(d(t),nM(d(t)))}function J(t){if(t===0)return b;{let e=b.slice(-t),n=b.slice(0,b.length-t);return e.concat(n)}}function w(t,e){a(2,arguments);let n=p(e);return g(t,-n)}var q=(t,e)=>{let n=t.find(({header:r})=>r?.includes?.("科目名称"))?.content??"",o=t.find(({header:r})=>r?.includes?.("科目名称(英語)"))?.content??"",u=t.find(({header:r})=>r?.includes?.("教員名"))?.content?.split?.(/,、,/)?.map?.(r=>r.replace(/ /g,"").trim())??[],l=t.find(({header:r})=>r?.includes?.("開講年度学期"))?.content??"",D={year:parseInt(l),quater:l.match(/\d+年(.*)$/)?.1??""},i=t.find(({header:r})=>r?.includes?.("曜日時限"))?.content??"",s=...G(i),x=parseInt(t.find(({header:r})=>r?.includes?.("単位"))?.content??""),y=f(t.find(({header:r})=>r?.includes?.("概要"))?.content??""),_=f(t.find(({header:r})=>r?.includes?.("目的"))?.content??""),R=f(t.find(({header:r})=>r?.includes?.("到達目標"))?.content??""),k=f(t.find(({header:r})=>r?.includes?.("履修上の注意"))?.content??""),j=f(t.find(({header:r})=>r?.includes?.("準備学習・復習"))?.content??""),N=f(t.find(({header:r})=>r?.includes?.("成績評価方法"))?.content??""),U=t.find(({header:r})=>r?.includes?.("教科書の使用有無"))?.content?.includes?.("Y")??!1,S=t.findIndex(({header:r})=>r?.includes?.("その他資料の使用有無")),F=f(S===-1?"":tS+1?.content??""),O=f(t.find(({header:r})=>r?.includes?.("授業計画"))?.content?.replace?.(/\s*\n\n\s*/g,` )??""),L=[...Array(15)].map((r,z)=>s.map(({day:V,hour:Z})=>{let c=A(w(e,1),V);switch(Z){case 1:c.setHours(9),c.setMinutes(0);break;case 2:c.setHours(10),c.setMinutes(40);break;case 3:c.setHours(13),c.setMinutes(10);break;case 4:c.setHours(14),c.setMinutes(50);break;case 5:c.setHours(16),c.setMinutes(20);break;case 6:c.setHours(18),c.setMinutes(10);break;case 7:c.setHours(19),c.setMinutes(50);break}return g(c,z*7)})),P=f(t.find(({header:r})=>r?.includes?.("実務経験"))?.content??""),B=t.find(({header:r})=>r?.includes?.("科目番号"))?.content??"",Y=t.pop()?.content??"";return{title:n,titleEn:o,instructors:u,semesterRaw:l,semester:D,hoursRaw:i,hours:s,credits:x,description:y,objectives:_,outcomes:R,prerequisites:k,preparationAndReview:j,evaluation:N,textbook:U,reference:F,plan:O,schedule:L,experience:P,num:B,code:Y}},f=t=>t.replace(/^\s*/mg,"").replace(/\s$/mg,"").replaceAll(
,"").replace(/[A-Za-z0-9]/g,e=>String.fromCharCode(e.charCodeAt(0)-65248)).replace(/\s?\[/g,"[").replace(/\s?\[/g,"[").replaceAll(".",.
).replace(/(\d+).\s*/g,"$1. ").replaceAll("・"," ").replaceAll(".","。").replaceAll("。",。
).replaceAll(",","、");function*G(t){for(let[,e,n]of t.matchAll(/(日|月|火|水|木|金|土)曜([1-7])限/g))yield{day:Q(e),hour:parseInt(n)}}var Q=t=>{switch(t){case"日":return 0;case"月":return 1;case"火":return 2;case"水":return 3;case"木":return 4;case"金":return 5;case"土":return 6}};function m(t,e){for(var n=t<0?"-":"",o=Math.abs(t).toString();o.length<e;)o="0"+o;return n+o}var K={y(t,e){let n=t.getUTCFullYear(),o=n>0?n:1-n;return m(e==="yy"?o%100:o,e.length)},M(t,e){let n=t.getUTCMonth();return e==="M"?String(n+1):m(n+1,2)},d(t,e){return m(t.getUTCDate(),e.length)},a(t,e){let n=t.getUTCHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(t,e){return m(t.getUTCHours()%12||12,e.length)},H(t,e){return m(t.getUTCHours(),e.length)},m(t,e){return m(t.getUTCMinutes(),e.length)},s(t,e){return m(t.getUTCSeconds(),e.length)},S(t,e){let n=e.length,o=t.getUTCMilliseconds(),u=Math.floor(o*Math.pow(10,n-3));return m(u,e.length)}},H=K;function $(t){let e=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return e.setUTCFullYear(t.getFullYear()),t.getTime()-e.getTime()}function C(t){a(1,arguments);var e=d(t);return!isNaN(e)}function T(t,e){a(2,arguments);let n=d(t).getTime(),o=p(e);return new Date(n+o)}function v(t,e){a(2,arguments);let n=p(e);return T(t,-n)}var W=/(\w)\1*|''|'(''|[^'])+('|$)|./g,X=/^'([^]*?)'?$/,tt=/''/g,et=/[a-zA-Z]/;function h(t,e){a(2,arguments);let n=d(t);if(!C(n))throw new RangeError("Invalid time value");let o=$(n),u=v(n,o),l=e.match(W);return l?l.map(i=>{if(i==="''")return"'";let s=i[0];if(s==="'")return nt(i);let x=H[s];if(x)return x(u,i);if(s.match(et))throw new RangeError("Format string contains an unescaped latin alphabet character "+s+"");return i}).join(""):""}function nt(t){let e=t.match(X);return e?e[1].replace(tt,"'"):t}var I=(t,e)=>{let n=${t}-${e.semester.year}${e.semester.quater.includes("前")?"F":"S"},o=new Date,u=Math.round(o.getTime()/1e3),l=h(o,"#yyyy-MM-dd HH:mm:ss"),D=e.schedule.flatMap((s,x)=>s.map(y=>⬜@${h(y,"yyyy-MM-dd")}T${h(y,"HH:mm")}D90 ${n}-${x+1}));return[{title:n,lines:[n,"table:basic information", Title ${e.title}, Title (en) ${e.titleEn}, Instructor ${e.instructors.map(s=>[${s}]).join(", ")}, Schedule ${e.semesterRaw} ${e.hoursRaw}, Course credits ${e.credits}, Course code ${e.code},"LETUS","Syllabus","","Descriptions",...e.description.split(
).map(s=> ${s}),"","Objectives",...e.objectives.split(
).map(s=> ${s}),"","Outcomes",...e.outcomes.split(
).map(s=> ${s}),"","Course notes prerequisites",...e.prerequisites.split(
).map(s=> ${s}),"","Preparation and review",...e.preparationAndReview.split(
).map(s=> ${s}),"","Evaluation",...e.evaluation.split(
).map(s=> ${s}),"",...e.textbook?["TextBooks"," ",""]:[],...e.reference?["Materials",...e.reference.split(
).map(s=> ${s}),""]:[],"Plan",...e.plan.split(
).map(s=> ${s}),...D.map(s=> ${s}),"",#${h(new Date,"yyyy-MM-dd HH:mm:ss")}].map(s=>({text:s,created:u}))}]};try{let t=window.prompt("授業情報ページの頭文字");if(t){let e=I(t,q(E(),new Date(2023,8,14))),n=new Blob([JSON.stringify({pages:e})],{type:"application/json"});window.open(URL.createObjectURL(n))}}catch(t){if(!(t instanceof Error))throw alert(JSON.stringify(t)),t;alert(${t.name} ${t.message} ${t.stack}`)}
JQueryの上書きを避けるため、IIFEでbuildする
code:copy.js
(()=>{var j=()=>{let e="class.admin.tus.ac.jp";if(location.host!==e)throw Error(This script can be only executed in "${e}");let t=document.getElementById("pkx02301:ch:table");if(!t)throw Error("シラバス照会window (#pkx02301:ch:table) が開かれていません");return Array.from(t.getElementsByClassName("rowStyle")).flatMap(s=>{let a=Array.from(s.getElementsByClassName("ui-widget-header")),i=Array.from(s.getElementsByClassName("ui-widget-content")),u=[];for(let f=0;f<Math.max(a.length,i.length);f++){let o={};af&&(o.header=af.innerText),if&&(o.content=if.innerText),u.push(o)}return u})};function q(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="object Date"}function b(e){let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="object Date"?new e.constructor(+e):typeof e=="number"||t==="object Number"||typeof e=="string"||t==="object String"?new Date(e):new Date(NaN)}function P(e){if(!q(e)&&typeof e!="number")return!1;let t=b(e);return!isNaN(Number(t))}function l(e,t){let n=e<0?"-":"",s=Math.abs(e).toString().padStart(t,"0");return n+s}var L={y(e,t){let n=e.getFullYear(),s=n>0?n:1-n;return l(t==="yy"?s%100:s,t.length)},M(e,t){let n=e.getMonth();return t==="M"?String(n+1):l(n+1,2)},d(e,t){return l(e.getDate(),t.length)},a(e,t){let n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n0;case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(e,t){return l(e.getHours()%12||12,t.length)},H(e,t){return l(e.getHours(),t.length)},m(e,t){return l(e.getMinutes(),t.length)},s(e,t){return l(e.getSeconds(),t.length)},S(e,t){let n=t.length,s=e.getMilliseconds(),a=Math.trunc(s*Math.pow(10,n-3));return l(a,t.length)}},U=/(\w)\1*|''|'(''|^')+('|$)|./g,z=/^'(^*?)'?$/,G=/''/g,J=/a-zA-Z/;function m(e,t){let n=b(e);if(!P(n))throw new RangeError("Invalid time value");let s=t.match(U);return s?s.map(a=>{if(a==="''")return"'";let i=a0;if(i==="'")return Z(a);let u=Li;if(u)return u(n,a);if(i.match(J))throw new RangeError("Format string contains an unescaped latin alphabet character "+i+"");return a}).join(""):""}function Z(e){let t=e.match(z);return t?t1.replace(G,"'"):e}function _(e){let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="object Date"?new e.constructor(+e):typeof e=="number"||t==="object Number"||typeof e=="string"||t==="object String"?new Date(e):new Date(NaN)}function K(e,t){return e instanceof Date?new e.constructor(t):new Date(t)}function w(e,t){let n=_(e);return isNaN(t)?K(e,NaN):(t&&n.setDate(n.getDate()+t),n)}function Q(e){let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="object Date"?new e.constructor(+e):typeof e=="number"||t==="object Number"||typeof e=="string"||t==="object String"?new Date(e):new Date(NaN)}function V(e,t){return e instanceof Date?new e.constructor(t):new Date(t)}function X(e,t){let n=Q(e);return isNaN(t)?V(e,NaN):(t&&n.setDate(n.getDate()+t),n)}function h(e,t){return X(e,-t)}function x(e){let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="object Date"?new e.constructor(+e):typeof e=="number"||t==="object Number"||typeof e=="string"||t==="object String"?new Date(e):new Date(NaN)}function ee(e,t){return e instanceof Date?new e.constructor(t):new Date(t)}function te(e,t){let n=x(e);return isNaN(t)?ee(e,NaN):(t&&n.setDate(n.getDate()+t),n)}function ne(e){return x(e).getDay()}function v(e,t){let n=t-ne(e);return n<=0&&(n+=7),te(e,n)}var re=Math.pow(10,8)*24*60*60*1e3,Ct=-re;var oe=3600,S=oe*24,Tt=S*7,se=S*365.2425,ae=se/12,Wt=ae*3;var N=(e,t)=>{let n=e.find(({header:r})=>r?.includes?.("名称"))?.content??"",s=e.find(({header:r})=>r?.includes?.("名称(英文)"))?.content??"",a=e.find(({header:r})=>r?.includes?.("教員名"))?.content?.split?.(/,、,/)?.map?.(r=>r.replace(/ /g,"").trim())??[],i=e.find(({header:r})=>r?.includes?.("開講年度学期"))?.content??"",u={year:parseInt(i),quater:i.match(/\d+年(.*)$/)?.1??""},f=e.find(({header:r})=>r?.includes?.("曜日時限"))?.content??"",o=...ce(f),g=parseInt(e.find(({header:r})=>r?.includes?.("単位"))?.content??""),d=p(e.find(({header:r})=>r?.includes?.("概要"))?.content??""),k=p(e.find(({header:r})=>r?.includes?.("目的"))?.content??""),M=p(e.find(({header:r})=>r?.includes?.("到達目標"))?.content??""),$=p(e.find(({header:r})=>r?.includes?.("履修上の注意"))?.content??""),H=p(e.find(({header:r})=>r?.includes?.("準備学習・復習"))?.content??""),C=p(e.find(({header:r})=>r?.includes?.("成績評価方法"))?.content??""),T=e.find(({header:r})=>r?.includes?.("教科書の使用有無"))?.content?.includes?.("Y")??!1,D=e.findIndex(({header:r})=>r?.includes?.("その他資料の使用有無")),W=p(D===-1?"":eD+1?.content??""),E=p(e.find(({header:r})=>r?.includes?.("授業計画"))?.content?.replace?.(/\s*\n\n\s*/g,` )??""),A=[...Array(15)].map((r,I)=>o.map(({day:B,hour:Y})=>{let c=v(h(t,1),B);switch(Y){case 1:c.setHours(8),c.setMinutes(50);break;case 2:c.setHours(10),c.setMinutes(30);break;case 3:c.setHours(13),c.setMinutes(0);break;case 4:c.setHours(14),c.setMinutes(40);break;case 5:c.setHours(16),c.setMinutes(20);break;case 6:c.setHours(18),c.setMinutes(0);break;case 7:c.setHours(19),c.setMinutes(40);break}return w(c,I*7)})),y=p(e.find(({header:r})=>r?.includes?.("実務経験"))?.content??"");y==="-"&&(y="");let R=e.find(({header:r})=>r?.includes?.("科目番号"))?.content??"",F=e.find(({header:r})=>r?.includes?.("授業コード"))?.content??"";return{title:n,titleEn:s,instructors:a,semesterRaw:i,semester:u,hoursRaw:f,hours:o,credits:g,description:d,objectives:k,outcomes:M,prerequisites:$,preparationAndReview:H,evaluation:C,textbook:T,reference:W,plan:E,schedule:A,experience:y,num:R,code:F}},p=e=>e.replace(/^\s*/mg,"").replace(/\s$/mg,"").replaceAll(
,"").replace(/[A-Za-z0-9]/g,t=>String.fromCharCode(t.charCodeAt(0)-65248)).replace(/\s?\[/g,"[").replace(/\s?\[/g,"[").replaceAll(".",.
).replace(/(\d+).\s*/g,"$1. ").replaceAll("・"," ").replaceAll(".","。").replaceAll("。",。
).replaceAll(",","、");function*ce(e){for(let[,t,n]of e.matchAll(/(日|月|火|水|木|金|土)曜([1-7])限/g))yield{day:ie(t),hour:parseInt(n)}}var ie=e=>{switch(e){case"日":return 0;case"月":return 1;case"火":return 2;case"水":return 3;case"木":return 4;case"金":return 5;case"土":return 6}};var O=(e,t)=>{let n=${e}-${t.semester.year}${t.semester.quater.includes("前")?"F":"S"},s=new Date,a=Math.round(s.getTime()/1e3),i=m(s,"#yyyy-MM-dd HH:mm:ss"),u=t.schedule.flatMap((o,g)=>o.map(d=>⬜@${m(d,"yyyy-MM-dd")}T${m(d,"HH:mm")}D90 ${n}-${g+1}));return[{title:n,lines:[n,"table:basic information", Title ${t.title}, Title (en) ${t.titleEn}, Instructor ${t.instructors.map(o=>[${o}]).join(", ")}, Schedule ${t.semesterRaw} ${t.hoursRaw}, Course credits ${t.credits}, Course code ${t.code},"LETUS",Syllabus,"","Descriptions",...t.description.split( ).map(o=> ${o}),"","Objectives",...t.objectives.split(
).map(o=> ${o}),"","Outcomes",...t.outcomes.split(
).map(o=> ${o}),"","Course notes prerequisites",...t.prerequisites.split(
).map(o=> ${o}),"","Preparation and review",...t.preparationAndReview.split(
).map(o=> ${o}),"","Evaluation",...t.evaluation.split(
).map(o=> ${o}),"",...t.textbook?["TextBooks"," ",""]:[],...t.reference?["Materials",...t.reference.split(
).map(o=> ${o}),""]:[],"Plan",...t.plan.split(
).map(o=> ${o}),...u.map(o=> ${o}),"",...t.experience?["Experience",...t.experience.split( ).map(o=> ${o}),""]:[],#${m(new Date,"yyyy-MM-dd HH:mm:ss")}].map(o=>({text:o,created:a}))}]};(async()=>{try{let e=window.prompt("授業情報ページの頭文字");if(e){let[t]=O(e,N(j(),new Date(2024,3,11)));await navigator.clipboard.writeText(t.lines.map(({text:n})=>n).join( ))}}catch(e){if(!(e instanceof Error))throw alert(JSON.stringify(e)),e;alert(${e.name} ${e.message}
${e.stack}`)}})();})();