-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cfc003
commit 3fb5e44
Showing
11 changed files
with
146 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Sample</title> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<style> | ||
.absolute { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
.relative { | ||
contain: strict; | ||
height: calc(100vh - 315px); | ||
-webkit-mask-image: linear-gradient(0deg,hsla(0,0%,100%,0),#fff 5%,#fff 95%,hsla(0,0%,100%,0)); | ||
mask-image: linear-gradient(0deg,hsla(0,0%,100%,0),#fff 5%,#fff 95%,hsla(0,0%,100%,0)); | ||
overflow-y: scroll; | ||
position: relative; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Congratulations 🎉, you have learned how to use Immersive Translate. Try pressing and holding the floating ball on the right side of the page, which will open the quick settings panel.</p> | ||
<p>🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉</p> | ||
<script src="../global-assets/mock_gm.js"></script> | ||
<script src="../immersive-translate.user.js"></script> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
function GM_getValue(name, defaultVal) { | ||
let value = localStorage.getItem(name) || defaultVal; | ||
try { | ||
return JSON.parse(value); | ||
} catch (error) { | ||
return value; | ||
} | ||
} | ||
|
||
function GM_setValue(name, value) { | ||
if (typeof value === "object") value = JSON.stringify(value); | ||
localStorage.setItem(name, value); | ||
} | ||
|
||
function GM_deleteValue(name) { | ||
localStorage.deleteValue(name); | ||
} | ||
|
||
function GM_listValues() { | ||
var keys = []; | ||
for (var i = 0; i < localStorage.length; i++) { | ||
keys.push(localStorage.key(i)); | ||
} | ||
return keys; | ||
} | ||
|
||
function GM_xmlhttpRequest(details) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open(details.method, details.url, true); | ||
|
||
// 设置请求头 | ||
if (details.headers) { | ||
for (var header in details.headers) { | ||
if (details.headers.hasOwnProperty(header)) { | ||
xhr.setRequestHeader(header, details.headers[header]); | ||
} | ||
} | ||
} | ||
|
||
// 处理响应 | ||
xhr.onload = function () { | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
// 请求成功,处理响应数据 | ||
console.log(JSON.parse(xhr.responseText)); | ||
if (details.onload) details.onload(xhr); | ||
} else { | ||
// 请求失败 | ||
console.error("Request failed: ", xhr.statusText); | ||
if (details.onerror) details.onerror(xhr); | ||
} | ||
}; | ||
|
||
// 处理网络错误 | ||
xhr.onerror = function () { | ||
console.error("Network error"); | ||
if (details.onerror) details.onerror(xhr); | ||
}; | ||
|
||
// 发送请求 | ||
xhr.send(details.data); // 如果你的方法是POST或PUT,并且有数据要发送 | ||
} | ||
|
||
function GM_registerMenuCommand(name, func, accessKey) { | ||
console.log(`Menu command registered: ${name}`); | ||
// 实际上,你需要在页面上添加一个用户界面元素,如按钮,并将 func 绑定为其点击事件处理程序 | ||
} | ||
|
||
function GM_addStyle(css) { | ||
var style = document.createElement("style"); | ||
style.type = "text/css"; | ||
style.innerHTML = css; | ||
document.head.appendChild(style); | ||
} | ||
|
||
function GM_openInTab(url, openInBackground) { | ||
window.open(url, "_blank"); | ||
} | ||
|
||
window.GM = { | ||
getValue: GM_getValue, | ||
setValue: GM_setValue, | ||
deleteValue: GM_deleteValue, | ||
listValues: GM_listValues, | ||
xmlhttpRequest: GM_xmlhttpRequest, | ||
registerMenuCommand: GM_registerMenuCommand, | ||
addStyle: GM_addStyle, | ||
openInTab: GM_openInTab, | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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