Skip to content

Commit 4ecac51

Browse files
committed
Refactor index.html to include a Content Security Policy and link to the new main.js; remove inline script for improved organization. Delete old main.js file to streamline codebase.
1 parent 737352c commit 4ecac51

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

app/src/main/assets/index.html

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,14 @@
33
<head>
44
<meta charset="UTF-8" />
55
<link rel="stylesheet" href="./styles.css" />
6+
<meta
7+
http-equiv="Content-Security-Policy"
8+
content="default-src * 'unsafe-inline' 'unsafe-eval'"
9+
/>
610
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
711
<title>Tauri App</title>
8-
<!-- <script type="module" src="./main.js" defer></script> -->
9-
<script>
10-
window.addEventListener('DOMContentLoaded', () => {
11-
console.log('DOMContentLoaded-----')
12-
const getdata = document.querySelector('#getdata')
13-
getdata.addEventListener('click', (e) => {
14-
e.preventDefault()
15-
console.log('getdata')
16-
fetch('https://api.github.com/users/octocat')
17-
.then((response) => response.json())
18-
.then((data) => {
19-
console.log('data', data)
20-
const greetMsgEl =
21-
document.querySelector('#greet-msg')
22-
greetMsgEl.textContent = data.login
23-
})
24-
.catch((error) => {
25-
console.error('error', error)
26-
})
27-
})
28-
})
29-
</script>
12+
<script src="main.js"></script>
3013
</head>
31-
3214
<body>
3315
<main class="container">
3416
<h1>Welcome to TauriMan</h1>
@@ -62,6 +44,7 @@ <h1>Welcome to TauriMan</h1>
6244
<input id="greet-input" placeholder="Enter a name..." />
6345
<button type="submit" id="getdata">GET DATA</button>
6446
</form>
47+
<button onclick="sayHello()">点击我</button>
6548
<p id="greet-msg"></p>
6649
<video
6750
src="https://files.pakeplus.com/test.mp4"

app/src/main/assets/js/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
console.log('main.js---')
2+
13
window.addEventListener('DOMContentLoaded', () => {
24
console.log('DOMContentLoaded-----')
35
const getdata = document.querySelector('#getdata')

app/src/main/assets/main.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function sayHello() {
2+
alert('你好,这是本地JS代码!')
3+
}
4+
5+
6+
console.log('main.js---')
7+
8+
window.addEventListener('DOMContentLoaded', () => {
9+
console.log('DOMContentLoaded-----')
10+
const getdata = document.querySelector('#getdata')
11+
getdata.addEventListener('click', (e) => {
12+
e.preventDefault()
13+
console.log('getdata')
14+
fetch('https://api.github.com/users/octocat')
15+
.then((response) => response.json())
16+
.then((data) => {
17+
console.log('data', data)
18+
const greetMsgEl = document.querySelector('#greet-msg')
19+
greetMsgEl.textContent = data.login
20+
})
21+
.catch((error) => {
22+
console.error('error', error)
23+
})
24+
})
25+
})

app/src/main/java/com/app/pakeplus/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class MainActivity : AppCompatActivity() {
6464
webView.settings.loadWithOverviewMode = true
6565
webView.settings.setSupportZoom(false)
6666

67-
6867
// clear cache
6968
webView.clearCache(true)
7069

0 commit comments

Comments
 (0)