Greasy Fork

Greasy Fork is available in English.

Bonnae News

for Bonnae broadcast on douban.com

当前为 2018-11-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bonnae News
// @namespace    https://github.com/harryhare/Bonnae-News
// @version      0.5.1
// @description  for Bonnae broadcast on douban.com
// @author       harryhare
// @match        https://www.douban.com/**
// @include      https://www.douban.com/**
// @icon         https://raw.githubusercontent.com/harryhare/Bonnae-News/master/index.png
// @grant        none
// ==/UserScript==


(function() {
	'use strict';

	var targets=document.querySelectorAll('.new-status .status-item[data-uid="1540691"] .mod .bd .status-saying blockquote p');

	/*
	http://upaste.me/xxxxx
	https://slexy.org/view/xxxxx
	https://paste2.org/xxxxx (注意代码区分大小写)
	https://paste.ee/p/xxxxx
	*/
	var url_prefix=new Map();
	url_prefix['upaste.me']='http://upaste.me/';
	url_prefix['slexy.org']='https://slexy.org/view/';
	url_prefix['paste2.org']='https://paste2.org/';
	url_prefix['paste.ee']='https://paste.ee/p/'
	const default_prefix='upaste.me';
	const max_code_length=100;

	for(let i=0;i<targets.length;i++){
		var t=targets[i];
		var content=t.textContent;
		if(content.length>max_code_length){
			continue;
		}
		var reg = /([a-zA-Z0-9]{4,})\s*\(([a-z0-9]+.[a-z]+)(\/p\/)?\)/g
		var reg2=/([a-zA-Z0-9]{10,})/g;
		var result=reg.exec(content);
		var href='';
		var find=false;
		if(result && result.length>2 && result[2]){
			href=url_prefix[result[2]]+result[1];
			find=true;
		}
		if(!find){
			result=reg2.exec(content);
			if(result && result.length>1){
				href=url_prefix[default_prefix]+result[1];
				find=true;
			}
		}
		if(find){
			var n1=document.createElement('a');
			var n2=document.createElement('blockquote');
			n2.appendChild(n1);

			n1.textContent=href;
			n1.setAttribute('href',href);
			t.parentElement.parentElement.appendChild(n2);
		}
	}
})();