Skip to content

Instantly share code, notes, and snippets.

@diggles
Last active May 19, 2019 10:59
Show Gist options
  • Save diggles/455bb9aa7312281b79a31e9a322076a2 to your computer and use it in GitHub Desktop.
Save diggles/455bb9aa7312281b79a31e9a322076a2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name RJ Code Highlight
// @namespace VoiceThread
// @version 0.2
// @description Makes RJ codes interactive
// @author Anon
// @match https://boards.4chan.org/*
// @grant GM_xmlhttpRequest
// @connect hvdb.me
// @require https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==
(function() {
'use strict';
$.noConflict();
jQuery( document ).ready(function( $ ) {
$.fn.replaceText = function( search, replace, text_only ) {
return this.each(function(){
var node = this.firstChild,
val,
new_val,
// Elements to be removed at the end.
remove = [];
// Only continue if firstChild exists.
if ( node ) {
// Loop over all childNodes.
do {
// Only process text nodes.
if ( node.nodeType === 3 ) {
// The original node value.
val = node.nodeValue;
// The new value.
new_val = val.replace( search, replace );
// Only replace text if the new value is actually different!
if ( new_val !== val ) {
if ( !text_only && /</.test( new_val ) ) {
// The new value contains HTML, set it in a slower but far more
// robust way.
$(node).before( new_val );
// Don't remove the node yet, or the loop will lose its place.
remove.push( node );
} else {
// The new value contains no HTML, so it can be set in this
// very fast, simple way.
node.nodeValue = new_val;
}
}
}
} while ( node = node.nextSibling );
}
// Time to remove those elements!
remove.length && $(remove).remove();
});
};
$('body *').replaceText(/rj\d{6}/ig, function(replace){ return '<rjcode code='+replace+'>'+replace+ '</rjcode>'; })
$('body').append(
$('<style>')
.append('.codeWindow input, hiddenForm, textarea { display: none; }')
.append('.codeWindow .col-md-6 { float: left; padding: 15px; }')
.append('.codeWindow hr { display: none; }')
.append('.codeWindow h2 { display: none; }')
.append('.codeWindow .col-md-10 { overflow: auto; }')
.append('.codeWindow label { width: 100px; float: left;}')
.append('.codeWindow ul { list-style: none; padding: 0; margin: 0;}')
.append('.codeWindow .col-md-10 { padding:0!important}')
.append('.codeWindow .form-group {overflow:auto; border-bottom: 1px solid #aaa; margin-bottom: 10px; padding-bottom: 10px; }')
.append('.codeWindow .infoLabel {width: 275px}')
.append('rjcode { background: url(https://hvdb.me/favicon.ico) no-repeat; padding-left: 18px; cursor: pointer; }')
.append('.codeWindow .hvdbButtons { background: #aaa; }')
.append('.codeWindow .hvdbButtons span { cursor: pointer; display: inline-block; margin: 10px 0 10px 15px; }')
.append('.rjSelected { font-weight: 700; }')
);
$('rjcode')
.on('click', function(sender){
sender.preventDefault();
$('.codeWindow').remove();
$('rjcode').removeClass('rjSelected');
let clickedCode = $(sender.target).addClass('rjSelected').attr('code');
$('body').append(
$('<div>')
.append(
$('<div>')
.addClass('hvdbButtons')
.append(
$('<span>')
.text('close')
.on('click', function(){ $('.codeWindow').remove(); })
)
.append(
$('<span>')
.text('hvdb')
.on('click', function(){ open('https://hvdb.me/Dashboard/WorkDetails/' + clickedCode); })
)
.append(
$('<span>')
.text('dlsite')
.on('click', function(){ open('https://www.dlsite.com/maniax/work/=/product_id/' + clickedCode); })
)
)
.addClass('codeWindow')
.css({
position: 'fixed',
top: 40, right: 5,
background: '#888',
width: '1000px'
})
.append('<div id="hvdb">loading...</div>')
);
GM_xmlhttpRequest({method: 'GET', url: 'https://hvdb.me/Dashboard/WorkDetails/' + clickedCode, onload: function(data){
//debugger;
let content = $(data.response).find('.container-fluid .row');
content.find('.form-group').each(function(index, item){
if(index > 4) $(item).remove();
});
content = content.html()
.replace(/img src="/gi, 'img src="https://hvdb.me')
.replace(/href="/gi, 'href="https://hvdb.me')
.replace(/<a /gi, '<a target="_blank" ');
$('#hvdb').html(content);
}});
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment