vkch

%%добавляет поддержку разметки вакабы&макабы вконтакте%%

目前為 2015-06-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         vkch
// @icon         https://2ch.hk/favicon.ico
// @namespace    vkch
// @version      0.4
// @description  %%добавляет поддержку разметки вакабы&макабы вконтакте%%
// @author       .dmitry
// @include      *://vk.com/*
// @require      http://code.jquery.com/jquery-latest.min.js
// @require      https://gf.qytechs.cn/scripts/386-waituntilexists/code/waitUntilExists.js?version=5026
// @encoding     utf-8
// ==/UserScript==

function vkchPOWER( htmlCollection )
{
	var rules =
	[
		// strike
		{ rule: /\[s\](.+?)\[\/s\]/gim, replacement: "<s>$1</s>" },
		// boldness
		{ rule: /\*\*(.+?)\*\*/gm, replacement: "<span style='font-weight: bold'>$1</span>" },
		{ rule: /\[b\](.+?)\[\/b\]/gim, replacement: "<span style='font-weight: bold'>$1</span>" },
		// italic
		{ rule: /\*(.+?)\*/gm, replacement: "<span style='font-style: italic'>$1</span>" },
		{ rule: /\[i\](.+?)\[\/i\]/gim, replacement: "<span style='font-style: italic'>$1</span>" },
		// underline
		{ rule: /__(.+?)__/gm, replacement: "<span style='text-decoration: underline'>$1</span>" },
		{ rule: /\[u\](.+?)\[\/u\]/gim, replacement: "<span style='text-decoration: underline'>$1</span>" },
		// overline
		{ rule: /\[o\](.+?)\[\/o\]/gim, replacement: "<span style='text-decoration: overline'>$1</span>" },
		// sup
		{ rule: /\[sup\](.+?)\[\/sup\]/gim, replacement: "<sup>$1</sup>" },
		// sub
		{ rule: /\[sub\](.+?)\[\/sub\]/gim, replacement: "<sub>$1</sub>" },
		// code
		// @todo: remove any markup from code block
		{ rule: /``(.+?)``/gm, replacement: "<code style='display: inline-block; border: 1px solid #2b587a; max-width: 100%; overflow: auto; padding: calc( 1ex ); white-space: nowrap'>$1</code>" },
		// spoiler
		{ rule: /%%(.+?)%%/gm, replacement: "<span style='padding: 1px 0px; background-color: #edf1f5; color: #edf1f5 !important; cursor: text' onmouseover='this.style.setProperty( \"color\", \"black\", \"important\" )' onmouseout='this.style.setProperty( \"color\", \"#edf1f5\", \"important\" )'>$1</span>" },
		{ rule: /\[spoiler\](.+?)\[\/spoiler\]/gim, replacement: "<span style='padding: 1px 0px; background-color: #edf1f5; color: #edf1f5 !important; cursor: text' onmouseover='this.style.setProperty( \"color\", \"black\", \"important\" )' onmouseout='this.style.setProperty( \"color\", \"#edf1f5\", \"important\" )'>$1</span>" },
		// quote
		{ rule: /(^|\<br[^\>]*\>)(|\s+)\&gt\;(.*?)(\<br[^\>]*\>|$)/gim, replacement: "$1<span style='color: darkgreen'>$2&gt;$3</span>$4" },
		// unmarked list -- need something better
		//{ rule: /(^|\<br[^\>]*\>)(|\s+)\*(.*?)(\<br[^\>]*\>|$)/im, replacement: "$1$2<li>$3</li>$4" },
	];
	for( var id in htmlCollection )
	{
		var htmlObject = htmlCollection[id];
		
		for( var id in rules )
		{
			if( rules[id].rule.test( htmlObject.innerHTML ) == true )
			{
				htmlObject.innerHTML = htmlObject.innerHTML.replace( rules[id].rule, rules[id].replacement );
			}
		}
	}
}

/* Instant Messages begings here */
// My Messages
function vkchIM( )
{
	$( "#im_content" ).unbind( "DOMNodeInserted", vkchIM ); // for the great justice
	vkchPOWER( $( ".im_msg_text" ) );
	$( "#im_content" ).bind( "DOMNodeInserted", vkchIM ); // after the great justice, for the Emperor!
}
$( "#im_content" ).waitUntilExists( vkchIM ); // FIRE!

// Messages Widget
function vkchWidgetIM( )
{
	$( ".fc_tab_log_msgs" ).unbind( "DOMNodeInserted", vkchWidgetIM ); // for the great justice
	vkchPOWER( $( ".fc_msg" ) );
	$( ".fc_tab_log_msgs" ).bind( "DOMNodeInserted", vkchWidgetIM ); // after the great justice, for the Emperor!
}
$( ".fc_tab_log_msgs" ).waitUntilExists( vkchWidgetIM ); // FIRE!
/* Instant Messages ends here */


/* Wall Posts and Comments begins here */
// Wall Posts
function vkchWallPosts( )
{
	$( "#page_wall_posts" ).unbind( "DOMNodeInserted", vkchWallPosts ); // for the great justice
	vkchPOWER( $( ".wall_post_text" ) );
	$( "#page_wall_posts" ).bind( "DOMNodeInserted", vkchWallPosts ); // after the great justice, for the Emperor!
}
$( "#page_wall_posts" ).waitUntilExists( vkchWallPosts ); // FIRE!

// Wall Posts in Feed
function vkchWallPostsInFeed( )
{
	$( "#feed_rows" ).unbind( "DOMNodeInserted", vkchWallPostsInFeed ); // for the great justice
	vkchPOWER( $( ".wall_post_text" ) );
	$( "#feed_rows" ).bind( "DOMNodeInserted", vkchWallPostsInFeed ); // after the great justice, for the Emperor!
}
$( "#feed_rows" ).waitUntilExists( vkchWallPostsInFeed ); // FIRE!

// Extended Wall Post
function vkchExtendedWallPost( )
{
	vkchPOWER( $( "#wl_post .wall_post_text" ) );
}
$( "#wl_post" ).waitUntilExists( vkchExtendedWallPost ); // FIRE!

// Wall Post in Instant Messenger
function vkchForwardedWallPost( )
{
	vkchPOWER( $( ".im_msg_media .wall_post_text" ) );
}
$( ".im_msg_media .wall_post_text" ).waitUntilExists( vkchForwardedWallPost ); // FIRE!

// Wall Comments
function vkchWallComments( )
{
	$( ".reply_table" ).unbind( "DOMNodeInserted", vkchWallComments ); // for the great justice
	vkchPOWER( $( ".wall_reply_text" ) );
	$( ".reply_table" ).bind( "DOMNodeInserted", vkchWallComments ); // after the great justice, for the Emperor!
}
$( ".reply_table" ).waitUntilExists( vkchWallComments ); // FIRE!
/* Wall Posts and Comments ends here */

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址