Skip to content

Commit 72cedaf

Browse files
committed
2 parents e1a767c + b26655d commit 72cedaf

File tree

2 files changed

+88
-71
lines changed

2 files changed

+88
-71
lines changed

tool/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@
127127
<script src="ss/app.js"></script>
128128
<script src="ss/printer-queue.js"></script>
129129
</body>
130-
</html>
130+
</html>

tool/ss/app.js

Lines changed: 87 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,93 @@
1-
var input,output,
2-
render=(val, type)=>{
1+
let queue = [],
2+
domObjects = {
3+
title:{value:()=>$("input.optionaltext").value},
4+
code:{value:()=>$("textarea#input").value},
5+
output:{value:()=>$("textarea.input_of_op").value},
6+
filename:{value:()=>$("input#filename").value},
7+
rtf:{value:()=>$("#rtf_op span").innerHTML},
8+
watermark:{value:()=>$("#wm span").innerHTML},
9+
rtfBool:{value:()=>$("#rtf_bool").value}
10+
};
11+
function PRINT(){
12+
let list = [...queue];
13+
let i = 0;
14+
if(list.length!=0){
15+
list.forEach(el=>{
16+
sessionStorage["l-"+i++]=JSON.stringify(el);
17+
})
18+
sessionStorage.list=i;
19+
let pbVal = $("select#p_b_p").value;
20+
console.log(pbVal)
21+
window.location.assign(
22+
"print.html?pb="+pbVal
23+
)
24+
}else{
25+
show_message("nothing listed for print")
26+
}
27+
}
28+
const addToQueue = () =>{
29+
let tmp = {};
30+
31+
Object.keys(domObjects).forEach(key=>{
32+
tmp[key]=domObjects[key].value()
33+
})
34+
tmp.title="• "+tmp.title;
35+
queue.push(tmp);
36+
updateUIqueue();
37+
},
38+
updateUIqueue = () =>{
39+
let html="",rtfDisplay,deleter=$("select#select_del");
40+
deleter.disabled=true;
41+
if(queue.length!=0){
42+
deleter.disabled=false;
43+
let i = 0;
44+
deleter.innerHTML="<option default>none</option>";
45+
queue.forEach(cq=>{
46+
deleter.innerHTML+=`<option>${i+1}</option>`;
47+
if(cq.rtfBool=="true"){rtfDisplay="inline"}else{rtfDisplay="none"}
48+
html+=`<div style="margin:0 20px;">
49+
<h3>
50+
${++i}.${cq.title}
51+
</h3>
52+
<div class="outputBlock" style="margin-top:10px">
53+
<p class="filenames"><span class="filename">${cq.filename}</span></p>
54+
<p class="input">${sendCodeHighlight(cq.code,cq.filename)}</p>
55+
<p class="output">${cq.output}</p>
56+
<p align="center" class="img">
57+
<span style="display: ${rtfDisplay};" class="imageOutput">
58+
${cq.rtf}
59+
</span>
60+
</p>
61+
<p class="wm" align="right">
62+
<span>
63+
${cq.watermark}
64+
</span>
65+
</p>
66+
</div></div>
67+
`
68+
})
69+
show_message("Added "+queue[queue.length-1].filename+" to list successfully");
70+
}else{
71+
html="Nothing found in queue"
72+
}
73+
$("div.queue #list").innerHTML=html;
74+
},
75+
del = index =>{
76+
if(index!="none")
77+
{
78+
queue.splice(index-1,1);
79+
console.log(queue);
80+
updateUIqueue();
81+
}
82+
},
83+
sendCodeHighlight=(val,lang)=>{
384
let htmlBlock="",htmlLine,tempBlock;
4-
if(type=="ip"){
5-
tempBlock=getHighlight(val,$("span.filename").innerText)
85+
tempBlock=getHighlight(val,lang)
686
size=(tempBlock.split("\n").length+"").length;
787
for(i in tempBlock.split("\n")){
8-
str = padLeadingZeros(parseInt(i)+1,size);
9-
htmlLine=str+". "+tempBlock.split("\n")[i]+"<br/>";
88+
str = "<span class='ln'>"+padLeadingZeros(parseInt(i)+1,size)+"</span>";
89+
htmlLine=str+tempBlock.split("\n")[i]+"<br>";
1090
htmlBlock+=htmlLine;
1191
}
12-
$("p.input").innerHTML=htmlBlock;
13-
}else{
14-
$("p.output").innerText=val;
15-
}
16-
},
17-
copyToClipboard=(but)=>{
18-
let range = new Range();
19-
range.setStart($("div.outputBlock"), 0);
20-
range.setEnd($("div.outputBlock"),10);
21-
document.getSelection().removeAllRanges();
22-
document.getSelection().addRange(range);
23-
document.execCommand('copy');
24-
document.getSelection().removeAllRanges();
25-
but.innerText="copied";
26-
setTimeout(e=>{
27-
but.innerText="Copy"
28-
},1000)
92+
return htmlBlock;
2993
};
30-
function padLeadingZeros(num, size) {
31-
var s = num+"";
32-
while (s.length < size) s = "0" + s;
33-
return s;
34-
}
35-
function getHighlight(code,filename){
36-
if(filename.includes(".")){
37-
try{
38-
code = hljs.highlight(code,{language:filename.split(".")[filename.split(".").length-1]}).value;
39-
}catch(e){
40-
code = code.replaceAll("<","&lt;");
41-
}
42-
return code;
43-
}
44-
code = code.replaceAll("<","&lt;");
45-
return code;
46-
}
47-
var checkURL = val =>{
48-
if(isValidUrl(val)==true){
49-
$("#fetch").style.display="block";
50-
}else{
51-
$("#fetch").style.display="none";
52-
}
53-
}
54-
var insertCode = url =>{
55-
$("textarea#input").disabled=true;
56-
let fp = fetch(url);
57-
fp.then(obj=>obj.text()).then(val=>{
58-
$("textarea#input").value=val;
59-
$("textarea#input").disabled=false;
60-
render($("textarea#input").value,'ip')
61-
})
62-
fp.catch(e=>{
63-
show_message("error while fetch");
64-
$("textarea#input").disabled=false;
65-
});
66-
67-
}
68-
const isValidUrl = urlString=> {
69-
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
70-
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
71-
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
72-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
73-
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
74-
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
75-
return !!urlPattern.test(urlString);
76-
}

0 commit comments

Comments
 (0)