Skip to content

Commit

Permalink
var name fix;
Browse files Browse the repository at this point in the history
  • Loading branch information
itorr committed Mar 24, 2020
1 parent 197e74f commit 4d3bb18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
22 changes: 11 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,32 @@ <h2>仓库地址</h2>
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
<script>
(()=>{
const APIURL = 'https://lab.magiconch.com/api/nbnhhsh/';
const Nbnhhsh = {};
const API_URL = 'https://lab.magiconch.com/api/nbnhhsh/';

const request = (method,url,data,onOver)=>{
let x = new XMLHttpRequest();
x.open(method,url);
x.setRequestHeader('content-type', 'application/json');
x.withCredentials = true;
x.onload = ()=> onOver(x.responseText?JSON.parse(x.responseText):x.responseText);
x.onload = ()=> onOver(x.responseText ? JSON.parse(x.responseText) : null);
x.send(JSON.stringify(data));
return x;
};

const Guess = {};
const guess = (text,onOver)=>{
text = text.trim();

if(Nbnhhsh[text]){
return onOver(Nbnhhsh[text]);
if(Guess[text]){
return onOver(Guess[text]);
}

if(guess._x){
guess._x.abort();
if(guess._request){
guess._request.abort();
}
app.loading = true;
guess._x = request('POST',APIURL+'guess',{text},data=>{
Nbnhhsh[text] = data;
guess._request = request('POST',API_URL+'guess',{text},data=>{
Guess[text] = data;
onOver(data);
app.loading = false;
});
Expand All @@ -132,7 +132,7 @@ <h2>仓库地址</h2>
return;
}

request('POST',APIURL+'translation/'+name,{text},()=>{
request('POST',API_URL+'translation/'+name,{text},()=>{
alert('感谢对好好说话项目的支持!审核通过后这条对应将会生效');
});
};
Expand All @@ -142,8 +142,8 @@ <h2>仓库地址</h2>
data: {
text:'',
tags:[],
loading:false,
show:false
loading:false,
},
methods: {
submitTran,
Expand Down
34 changes: 17 additions & 17 deletions nbnhhsh.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@

((htmlText,cssText)=>{

const APIURL = 'https://lab.magiconch.com/api/nbnhhsh/';
const Nbnhhsh = {};
const API_URL = 'https://lab.magiconch.com/api/nbnhhsh/';

const request = (method,url,data,onOver)=>{
let x = new XMLHttpRequest();
x.open(method,url);
x.setRequestHeader('content-type', 'application/json');
x.withCredentials = true;
x.onload = ()=> onOver(x.responseText?JSON.parse(x.responseText):x.responseText);
x.onload = ()=> onOver(x.responseText ? JSON.parse(x.responseText) : null);
x.send(JSON.stringify(data));
return x;
};

const Guess = {};
const guess = (text,onOver)=>{
text = text.trim();

if(Nbnhhsh[text]){
return onOver(Nbnhhsh[text]);
if(Guess[text]){
return onOver(Guess[text]);
}

if(guess._x){
guess._x.abort();
if(guess._request){
guess._request.abort();
}

app.loading = true;
guess._x = request('POST',APIURL+'guess',{text},data=>{
Nbnhhsh[text] = data;
guess._request = request('POST',API_URL+'guess',{text},data=>{
Guess[text] = data;
onOver(data);
app.loading = false;
});
Expand All @@ -53,7 +53,7 @@
return;
}

request('POST',APIURL+'translation/'+name,{text},()=>{
request('POST',API_URL+'translation/'+name,{text},()=>{
alert('感谢对好好说话项目的支持!审核通过后这条对应将会生效');
});
};
Expand All @@ -68,7 +68,7 @@
}
};

const setPosition = ()=>{
const fixPosition = ()=>{
let rect = getSelection().getRangeAt(0).getBoundingClientRect();

let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
Expand Down Expand Up @@ -97,7 +97,7 @@
return;
}

setPosition();
fixPosition();

guess(text,data=>{
if(!data.length){
Expand All @@ -110,16 +110,16 @@
setTimeout(timer,300);
};

const handle = ()=>{
const _nbnhhsh = ()=>{
setTimeout(nbnhhsh,1);
};

document.body.addEventListener('mouseup',handle);
document.body.addEventListener('keyup',handle);
document.body.addEventListener('mouseup',_nbnhhsh);
document.body.addEventListener('keyup',_nbnhhsh);

const createEl = (html)=>{
createEl._el.innerHTML = html;
let el=createEl._el.children[0];
let el = createEl._el.children[0];
document.body.appendChild(el);
return el;
};
Expand All @@ -134,8 +134,8 @@
el,
data: {
tags:[],
loading:false,
show:false,
loading:false,
top:0,
left:0
},
Expand Down

0 comments on commit 4d3bb18

Please sign in to comment.