Facebook帖文列表
// ==UserScript==
// @name Facebook帖文列表
// @namespace http://tampermonkey.net/
// @version 2024-02-25
// @description try to take over the world!
// @author You
// @match https://mbasic.facebook.com/profile/timeline/stream/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=facebook.com
// @require http://cdn.bootcss.com/jquery/1.11.2/jquery.js
// @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
function sleep(number){
var now = new Date();
var exitTime = now.getTime() + number * 1000;
while (true) {
now = new Date();
if(now.getTime() > exitTime)
return
}
}
function waitAndRemove(iframe) {
return new Promise(resolve => {
const ListenMessage= (e)=> {
// if(e.source === iframe.contentWindow){
if(e.data==='close_window' && e.source === iframe.contentWindow){
window.removeEventListener('message', ListenMessage)
// 停止10秒
sleep(10)
//关闭窗口代码
iframe.remove();
}
resolve()
// }
};
window.addEventListener('message', ListenMessage);
});
}
(function() {
'use strict';
var monkey_url = 'http://127.0.0.1:8883/itemList';
elmGetter.selector($);
elmGetter.each('section article', company_name => {
// console.log(company_name);
console.log('page is fully loaded');
// elmGetter.each('ul#list-container li .list-info a.shop-name', company_name => {
// var shop_url = company_name[0].innerText;
var dataList = [];
var content = company_name.find('div.cd span').text()
var full_content = 'https://mbasic.facebook.com' + company_name.find('a.cq.cr').attr('href')
var timeline = company_name.find('abbr').text()
var emoji = company_name.find('a.cq.cr').attr('aria-label')
// content = 'https:' + content
dataList.push({
'帖文内容':content,
'帖文全文链接':full_content,
'帖文时间':timeline,
'帖文表情':emoji
})
// 如果不存在,则创建一个 iframe
var iframe = document.createElement('iframe');
//iframe.sandbox = 'allow-same-origin allow-scripts allow-popups allow-forms';
iframe.id = 'Autopage_iframe';
iframe.src = full_content;
console.info(iframe.src)
document.documentElement.appendChild(document.createElement('style')).textContent = 'iframe#Autopage_iframe {position: absolute !important; top: -9999px !important; left: -9999px !important; width: 100% !important; height: 100% !important; border: none !important; z-index: -999 !important;}';
document.documentElement.appendChild(iframe);
// 启动iframe关闭逻辑
(async function() {
await waitAndRemove(iframe);
})();
if (dataList.length > 0){
console.log(dataList);
GM_xmlhttpRequest({
method: "POST",
url: monkey_url,
data : JSON.stringify(dataList),
onload: function(response) {
//这里写处理函数
console.log(response);
console.log(dataList);
//window.close();
}
});
}
});
// Your code here...
})();