Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
h3786010 authored Oct 9, 2024
1 parent 0a05da0 commit a26ca4c
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions onesignal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="manifest" href="manifest.json"/>
<title>WebPush</title>
<style>
#output {
/* 設定自動換行 */
white-space: pre-wrap; /* 保留空白和換行符號 */
word-wrap: break-word; /* 長字詞自動換行 */
width: 100%; /* 控制寬度,以便換行 */
background-color: #f0f0f0; /* 背景色以便於查看 */
padding: 10px; /* 增加一些內邊距 */
border: 1px solid #ccc; /* 增加邊框 */
max-height: 300px; /* 設定最大高度 */
overflow-y: auto; /* 內容超出時出現滾動條 */
font-family: monospace;
box-sizing: border-box;
}
</style>
</head>
<body>
OneSignal ID:<br>
<span id="onesignal_id"></span><br>
Subscription ID:<br>
<span id="subscription_id"></span><br>

<div id="output"></div>

<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
Expand All @@ -19,9 +32,22 @@
await OneSignal.init({
appId: "d05bc6c0-138a-4b4f-b0f9-b7ea01d40312",
});
document.getElementById('onesignal_id').innerText = OneSignal.User.onesignalId;
document.getElementById('subscription_id').innerText = OneSignal.User.PushSubscription.id;
logOnScreen("OneSignal ID:"+OneSignal.User.onesignalId);
logOnScreen("Subscription ID:"+OneSignal.User.PushSubscription.id);
});
</script>
<script>
// 自訂的 console.log 替代函數
function logOnScreen(message) {
// 顯示在畫面上,最新的訊息在最前面
const outputDiv = document.getElementById("output");
const newMessage = document.createElement("p");
newMessage.textContent = message;
outputDiv.prepend(newMessage); // 將新訊息插入到最前面

// 同時在控制台顯示
console.log(message);
}
</script>
</body>
</html>

0 comments on commit a26ca4c

Please sign in to comment.