Greasy Fork

Greasy Fork is available in English.

分享到饭否

将网页标题和链接分享到饭否

当前为 2024-10-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         分享到饭否
// @namespace    http://tampermonkey.net/
// @version      0.5
// @icon         http://static.fanfou.com/favicon.ico
// @description  将网页标题和链接分享到饭否
// @author       Jing Wang
// @contact      [email protected]
// @license      GPL-3.0
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to process the title
    function processTitle(title) {
        // Replace "- cnBeta.COM 移动版(WAP)" with "- cnBeta"
        title = title.replace("- cnBeta.COM 移动版(WAP)", "- cnBeta");

        // Remove "(X+ 封私信 / Y 条消息)" pattern, where X and Y can be any number
        title = title.replace(/\(\d+\+?\s*封私信\s*\/\s*\d+\s*条消息\)/g, "");

        return title.trim(); // Trim any leading or trailing whitespace
    }

    // Create share button
    let shareButton = document.createElement('button');
    shareButton.textContent = '分享到饭否';
    shareButton.style.position = 'fixed';
    shareButton.style.bottom = '55px';
    shareButton.style.right = '55px';
    shareButton.style.zIndex = '9999';
    shareButton.style.padding = '10px';
    shareButton.style.backgroundColor = '#0FACD5';
    shareButton.style.color = 'white';
    shareButton.style.border = 'none';
    shareButton.style.borderRadius = '5px';
    shareButton.style.cursor = 'pointer';

    // Add click event listener
    shareButton.addEventListener('click', function() {
        let title = processTitle(document.title);
        let url = window.location.href;

        let shareText = encodeURIComponent(title);
        let fanfouUrl = `http://fanfou.com/sharer/image?u=${encodeURIComponent(url)}&t=${shareText}`;

        window.open(fanfouUrl, '_blank');
    });

    // Add button to the page
    document.body.appendChild(shareButton);
})();