亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Javascript 根據上次更新的網頁向不和諧發送通知

Javascript 根據上次更新的網頁向不和諧發送通知

梵蒂岡之花 2022-12-02 10:50:16
我正在嘗試創建一個頁面,當它被更新時,它會向不和諧的頻道發送通知。我有一個帶有按鈕的工作頁面,該按鈕會向 discord 發送通知(使用 webhooks 和 javascript)。我堅持使用 document.lastModified 來檢測頁面的最后更新時間,以便它可以執行 onclick=sendMessage()。對此的任何/所有幫助將不勝感激。-馬特我的代碼<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Discord Webhook Tutorial</title>  </head>  <body>    <button onclick="sendMessage()">Send</button>  </body>  <script>  mess1= document.lastModified;  math=99;  x = hidden(mess1);  if (x == true)     {         function sendMessage() {      var request = new XMLHttpRequest();      request.open("POST", "https://discordapp.com/api/webhooks/736073177125355570/yn5upyFa_7IkqwRXlO9XPzooIyMWkqM7wIXcIjqSR6SlhYD8eBCWOm7vEVl4vmNjQBxL");      request.setRequestHeader('Content-type', 'application/json');      var params = {        username: "Update Bot",        avatar_url: "",        content: "Testing bot... updating..."      }      request.send(JSON.stringify(params));    }         }  </script></html>
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

您需要將lastModified值存儲在某處以便能夠對其進行比較。


您在 DOM 中擁有的唯一值是當前值。


你可以這樣做:


const current = document.lastModified;


// Get the last known modified timestamp

const previous = localStorage.getItem('lastModified');


// Update the current modified timestamp

localStorage.setItem('lastModified', current);


// If they differ, trigger the webhook

if (current !== previous) { 

  doTheXHRThing();

}


查看完整回答
反對 回復 2022-12-02
  • 1 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號