I'm using a bookmarklet to send the current page source to a server function which then processes it (stores it, no information needs to be returned to the user).
Warning: ugly Javascript ahead, it's not a language I normally need to use.
Here's the bookmarklet, pretty-printed for ease of reading:
javascript: (function () {
var h = document.documentElement.innerHTML;
function c(a, b) {
var c = document.createElement("textarea");
c.name = a;
c.value = b;
d.appendChild(c)
}(document), d = document.createElement("form");
d.method = "POST";
d.action = "http://example.com/do.php";
d.enctype = "multipart/form-data";
d.target = "_blank";
c("h", h);
c("u", "1234");
document.body.appendChild(d);
d.submit();
})();
This basically works, "do.php" receives the head and body sections in form variable h.
ただし、各ページで 1 回しか機能しないようです。同じページに対してブックマークレットを 2 回押しても、何も起こりません。ページがリロードされると、再び機能します。リセットしなければならないものはありますか?(もちろん 1 回実行するだけで十分ですが、2 回目に実行したときにユーザーにフィードバックを提供するとよいでしょう)。
次に、これにより新しいタブ/ウィンドウがポップアップします。do.php に javascript を返してウィンドウを閉じさせることで、これを回避できます (注: これはテスト目的であり、実際のコードではありません)。
<?php
$page = $_REQUEST['h'];
file_put_contents('/tmp/work.txt', $page);
echo '<script type="text/javascript">window.close();</script>"';
?>
醜い。新しいタブをすばやくフラッシュすると、それはなくなります。より良いアプローチはありますか?「成功」メッセージはいいのですが、それを組み込む方法がわかりません。