// ==UserScript==
// @name 便捷背诵
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 对古诗文网进行辅助。可快速打开已经设定的文章链接。
// @author Pikaqian
// @match https://so.gushiwen.cn/*
// @match https://www.gushiwen.cn/
// @icon http://img1.baidu.com/it/u=2412192355,2922173485&fm=253&app=138&f=JPEG?w=110&h=110
// @grant none
// ==/UserScript==
(function() {
'use strict';
let style = document.createElement('style')
document.body.appendChild(style);
style.textContent=`
#black{
position:fixed;
height:100%;
width:100%;
background-color:#000;
opacity:0;
top:0px;
left:0px;
display:none;
cursor:pointer;
transition: 0.5s;
}
#text{
position: fixed;
height: 100%;
width: 210px;
background-color: #f0efe2;
left: -220px;
top: 0px;
transition: 0.2s;
overflow:auto;
z-index:1;
}::-webkit-scrollbar{width:5px;}::-webkit-scrollbar-thumb{background:rgba(117,117,117,0.7);}
#content{
font-size:14px;
background-color:none;
position:fixed;
cursor:pointer;
top:0px;
left:30px;
display:none;
}
#button{
height:15px;
width:40px;
border-bottom-right-radius:21px;
border-top-right-radius:21px;
color:#fff;
padding:6px;
opacity:.20;
left:-35px;
cursor:pointer;
transform-origin:0px 17px;
transition: 0.2s;
position:fixed;
z-index:2;
font-size:14px;
top:38%;
background:#000
}
`
function setCookie(cname,cvalue,exdays){//设置cookie
var cookie_all=cname
/*
for(var i=0;i<20;i++){
cookie_all=cookie_all+"1"
}
*/
//exdays=-1
if(exdays!=-1){
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
cookie_all=cname+"="+cvalue+"; "+expires+";path=/"
}
else{
cookie_all=cname+"="+cvalue+"; "+exdays+";path=/"
}
document.cookie = cookie_all;
}
//————————————————————————————————调取cookie
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)==0){
return c.substring(name.length,c.length);
}
}
return "";
}
if(getCookie("remember")==""){
setCookie("remember","0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",365)
var fontColor=getCookie("remember").split(",")
}
else{
fontColor=getCookie("remember").split(",")
}
function addText(num,text,href){
var content=document.createElement("content"+num)
content.innerText=text
content.id="content"
content.className="content"
content.href=href
content.style.top=num*30+"px"
if(fontColor[num-1]==1){
content.style.color="#f00"
}
document.getElementById("text").appendChild(content)
}
var check=0//0为尚未展开,将要展开;1为已经展开,将要合上
document.body.appendChild(style)
var text=document.createElement("text")
text.id="text"
document.body.appendChild(text)
// var button=document.createElement("a")
// button.id="button"
// document.body.appendChild(button)
var button = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var path13 = document.createElementNS("http://www.w3.org/2000/svg", 'path');
button.setAttribute("aria-hidden","true");
button.setAttribute('viewbox', '0 0 24 24');
button.setAttribute('width', '24px');
button.setAttribute('height', '24px');
path13.setAttribute('d','M423.1984 640a83.84 83.84 0 0 1-64-28.8 259.84 259.84 0 0 1-26.88-308.48L441.1184 128a261.12 261.12 0 1 1 448 272l-35.2 57.6a83.84 83.84 0 1 1-145.92-90.24l35.2-57.6a92.8 92.8 0 0 0-158.72-96.64L476.9584 389.76a92.8 92.8 0 0 0 9.6 109.44 83.84 83.84 0 0 1-64 139.52zM357.9184 1024A261.12 261.12 0 0 1 135.1984 626.56L166.5584 576a83.84 83.84 0 1 1 144 87.68l-31.36 51.2a92.8 92.8 0 0 0 30.72 128 91.52 91.52 0 0 0 70.4 10.88 92.16 92.16 0 0 0 57.6-41.6L545.4384 634.24a93.44 93.44 0 0 0-6.4-105.6A83.84 83.84 0 1 1 673.4384 424.96a262.4 262.4 0 0 1 17.28 296.96L581.2784 896A259.84 259.84 0 0 1 417.4384 1016.32a263.68 263.68 0 0 1-59.52 7.68z')
path13.style.transform="scale(0.0124) translate(2250px, -43px) rotate(17deg)"
path13.setAttribute('fill','#fff');
button.appendChild(path13);
button.id = 'button';
document.body.appendChild(button);
addText(1,"————古文————","")
addText(2,"赤壁赋","https://so.gushiwen.cn/shiwenv_4cac23b07849.aspx")
addText(3,"答司马谏议书","https://so.gushiwen.cn/shiwenv_b09aa5c9b747.aspx")
addText(4,"登泰山记","https://so.gushiwen.cn/shiwenv_8bf5847fffd5.aspx")
addText(5,"阿房宫赋","https://so.gushiwen.cn/shiwenv_0456af8aceec.aspx")
addText(6,"六国论","https://so.gushiwen.cn/shiwenv_077582755824.aspx")
addText(7,"谏太宗十思疏","https://so.gushiwen.cn/shiwenv_3827a21544f0.aspx")
addText(8,"劝学","https://so.gushiwen.cn/shiwenv_c743b1310a1c.aspx")
addText(9,"师说","https://so.gushiwen.cn/shiwenv_178197fd7202.aspx")
addText(10,"侍坐","https://so.gushiwen.cn/shiwenv_736e296de7fd.aspx")
addText(11,"————诗词————","")
addText(12,"登高","https://so.gushiwen.cn/shiwenv_eeb217f8cb2d.aspx")
addText(13,"登岳阳楼","https://so.gushiwen.cn/shiwenv_c05fb9a17f71.aspx")
addText(14,"短歌行","https://so.gushiwen.cn/shiwenv_35000de73cdb.aspx")
addText(15,"归园田居","https://so.gushiwen.cn/shiwenv_a537ff195683.aspx")
addText(16,"桂枝香·金陵怀古","https://so.gushiwen.cn/shiwenv_17a86f6c536a.aspx")
addText(17,"念奴娇·赤壁怀古","https://so.gushiwen.cn/shiwenv_5fb51378286c.aspx")
addText(18,"念奴娇·过洞庭","https://so.gushiwen.cn/shiwenv_8d26eae2cfdf.aspx")
addText(19,"梦游天姥吟留别","https://so.gushiwen.cn/shiwenv_05e2f6fc757c.aspx")
addText(20,"琵琶行","https://so.gushiwen.cn/shiwenv_0581b0ba8bb4.aspx")
addText(21,"鹊桥仙·纤云弄巧","https://so.gushiwen.cn/shiwenv_e83cadaaf394.aspx")
addText(22,"涉江采芙蓉","https://so.gushiwen.cn/shiwenv_c72d94b49cc6.aspx")
addText(23,"声声慢","https://so.gushiwen.cn/shiwenv_f82821b9d569.aspx")
addText(24,"诗经·静女","https://so.gushiwen.cn/shiwenv_87e447468c9e.aspx")
addText(25,"永遇乐·京口北固亭怀古","https://so.gushiwen.cn/shiwenv_12e69f000057.aspx")
addText(26,"虞美人·春花秋月何时了","https://so.gushiwen.cn/shiwenv_3574610d74e0.aspx")
var block=document.createElement("a")
block.style.position="fixed"
block.style.top=27*30+2+"px"
block.style.width="1px"
block.style.height="1px"
block.style.backgroundColor="#fff"
block.id="block"
document.getElementById("text").appendChild(block)
var black=document.createElement("black")
black.id="black"
document.body.appendChild(black)
button.addEventListener('mouseenter',function(e){
button.style.transform="translate(15px,0px)"
})
button.addEventListener('mouseleave',function(e){
button.style.transform="translate(0px,0px)"
})
button.addEventListener('click',function(e){
var content=document.getElementsByClassName("content")
if(check==0){
text.style.transform="translate(220px,0px)"
for(var i=0;i<content.length;i++){
content[i].style.display="block"
}
document.getElementById("black").style.display="block"
setTimeout(function () {
document.getElementById("black").style.opacity="0.3"
}, 0.1);
check=1
}
else if(check==1){
text.style.transform="translate(0px,0px)"
document.getElementById("black").style.opacity="0"
setTimeout(function () {
document.getElementById("black").style.display="none"
}, 300);
check=0
}
})
window.addEventListener('click',function(e){
if(e.target.id=="content"&&e.target.href!=""){
if(e.ctrlKey==true){
var open="_block"
}
else{
open="_self"
}
//alert(e.target.href)
window.open(e.target.href,open)
}
})
window.addEventListener('contextmenu',function(e){
if(e.ctrlKey!=true){
if(e.target.id=="content"&&e.target.href!=""){
if(e.target.style.color=="rgb(0, 0, 0)"||e.target.style.color==""){
e.target.style.color="#f00"
fontColor[parseInt(e.target.tagName.match(/\d{1,2}/)[0])-1]="1"
var cookie=""
for(var i=0;i<fontColor.length;i++){
if(fontColor[i]!=""){
cookie=cookie+fontColor[i]+","
}
}
setCookie("remember",cookie,365)
}
else{
e.target.style.color="#000"
fontColor[parseInt(e.target.tagName.match(/\d{1,2}/)[0])-1]="0"
cookie=""
for(var j=0;j<fontColor.length;j++){
if(fontColor[j]!=""){
cookie=cookie+fontColor[j]+","
}
}
setCookie("remember",cookie,365)
}
event.preventDefault()
}
}
else{
window.open("https://cn.bing.com/search?q="+e.target.innerText+"理解性默写","_blank")
event.preventDefault()
}
})
document.getElementById("black").addEventListener('click',function(e){
text.style.transform="translate(0px,0px)"
document.getElementById("black").style.opacity="0"
setTimeout(function () {
document.getElementById("black").style.display="none"
}, 300);
check=0
})
})();