Skip to content

Commit

Permalink
opti: docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hellosean1025 committed Oct 14, 2017
1 parent caf915f commit 1b46e96
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 64 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "cross-request",
"description": "A chrome extension that gives the html page cross-domain request capability",
"version": "2.2",
"version": "2.3",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
Expand Down
97 changes: 69 additions & 28 deletions popup.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,76 @@
<!doctype html>
<html>
<head>
<title>crossRequest</title>
<meta charset="utf8"/>
<style>
*{margin:8px;}
body {font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif; font-size: 100%;}
.main{width:320px;}
.content{line-height: 25px;min-height: 100px;}
.add{line-height:40px;margin-bottom: 20px;}
.add input{width:200px;line-height:25px;}
.add button{width:70px;line-height:25px;}
.url{min-width: 200px; display: inline-block}
.del{cursor:pointer}
</style>
</head>
<body>
<div class="main">
<h4>Allow Host:</h4>
<div class="content" id="urls">

<head>
<title>crossRequest</title>
<meta charset="utf8" />
<style>
* {
margin: 8px;
}

a {
text-decoration: none
}

body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}

.main {
width: 320px;
}

.content {
line-height: 25px;
min-height: 100px;
}

.add {
line-height: 40px;
margin-bottom: 20px;
}

.add input {
width: 200px;
line-height: 25px;
}

.add button {
width: 70px;
line-height: 25px;
}

.url {
min-width: 200px;
display: inline-block
}

.del {
cursor: pointer
}
</style>
</head>

<body>
<div class="main">

<p>A chrome extension that gives the html page cross-domain request capability. </p>
<p>If you need Help, <a href="https://github.com/YMFE/cross-request" target="_blank">follow the page.</a></p>
<br>
<!-- <div class="content" id="urls">
</div>
</div>
<div class="add" id="add">
</div> -->

</div>
<!-- <div class="add" id="add">
<input />
<button class="submit">Add Host</button>
</div>
<script src="jquery-3.1.1.js"></script>
<script src="popup.js"></script>
</div> -->
<!-- <script src="jquery-3.1.1.js"></script>
<script src="popup.js"></script> -->

</body>
</html>
</body>

</html>
39 changes: 4 additions & 35 deletions response.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,47 +211,16 @@ function yResponse() {
})
}

function isAllowHost() {
chrome.runtime.sendMessage({ action: 'get', name: localStorageKey }, function (res) {
try {
try {
res = JSON.parse(res);
} catch (e) {
res = null;
}
if (!res || Object.keys(res).length === 0) {
res = { '*': true };
chrome.runtime.sendMessage({ action: 'set', name: localStorageKey, value: JSON.stringify(res) })
}

var flag = false;
for (var name in res) {
name = name.replace(/\*/, ".*?");
var nameRegexp = new RegExp(name);
if (nameRegexp.test(location.hostname)) {
flag = true;
}
}
var crossRequestSign = document.getElementById('cross-request-sign');
if ((flag || crossRequestSign) && yRequestDom) {
setInterval(function () {
yResponse()
}, 100)
}
} catch (e) {
console.error(e)
}
})

}

//因注入 index.js ,需要等到 indexScript 初始化完成后执行
var findDom = setInterval(function () {
try {
yRequestDom = document.getElementById(container);
if (yRequestDom) {
clearInterval(findDom)
yRequestDom.setAttribute('key', 'yapi');
isAllowHost();
setInterval(function () {
yResponse()
}, 100)
}

} catch (e) {
Expand Down

0 comments on commit 1b46e96

Please sign in to comment.