Skip to content

Instantly share code, notes, and snippets.

@journey-ad
Last active March 15, 2024 18:33
Show Gist options
  • Star 71 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save journey-ad/5d3021fd40db75de2df827b876ef5b7e to your computer and use it in GitHub Desktop.
Save journey-ad/5d3021fd40db75de2df827b876ef5b7e to your computer and use it in GitHub Desktop.
哔站直播间的2233娘挂件替换为全裸版本
// ==UserScript==
// @name 哔站直播全裸2233娘
// @description 哔站直播间的2233娘挂件替换为全裸版本
// @description:zh-TW 嗶站直播間的2233娘掛件替換為全裸版本
// @namespace https://github.com/journey-ad
// @author journey-ad
// @include *://live.bilibili.com/*
// @require https://cdn.jsdelivr.net/jquery/1.12.4/jquery.min.js
// @require https://cdn.jsdelivr.net/gh/journey-ad/blog-img/libs/2233.zenra/live2d.js?v=1.1.9
// @version 1.1.9
// @license GPL v2
// @run-at document-end
// @grant none
// ==/UserScript==
(function(){
'use strict';
//监听DOM树变化
var observeDOMChanges = (function(){
var flag = true;
var ts = Date.now();
// 对变化的 dom 的操作
var changedHandler = function (element) {
if(flag && document.querySelectorAll('canvas.haruna-canvas').length > 0){
console.log('发现2233,开始替换');
//插旗
flag = false;
//移除原有的画布
var canvas = document.querySelectorAll('canvas.haruna-canvas')[0];
var parent = canvas.parentElement;
parent.removeChild(canvas);
//然后新建一个
var newcanvas = document.createElement('canvas');
newcanvas.id = 'live2d';
newcanvas.className = 'haruna-canvas';
newcanvas.width = 440;
newcanvas.height = 500;
//宽高样式设为画布的一半 优化高分屏显示效果
newcanvas.style.width = '220px';
newcanvas.style.height = '250px';
parent.insertBefore(newcanvas, parent.firstChild);
//看看是22还是33
var type = '22';
$.ajax({
type: "GET",
url: String.format('https://api.live.bilibili.com/live/getRoomKanBanModel?roomid={0}', BilibiliLive.ROOMID),
async: false,
success : function(data) {
type = data.label || type;
}
});
var jsonUrl = String.format('https://cdn.jsdelivr.net/gh/journey-ad/blog-img/libs/2233.zenra/{0}/{0}.zenra{1}.json?v1', type, (window.devicePixelRatio > 1 ? '@2x' : ''));
//加载没穿衣服的2233
loadlive2d("live2d", jsonUrl);
//使其支持拖动
var _move = false;
var ismove = false;
var _x, _y;
$(".live-haruna-ctnr").mousedown(function(e){
_move = true;
_x = e.pageX-parseInt($(".live-haruna-ctnr").css("left"));
_y = e.pageY-parseInt($(".live-haruna-ctnr").css("top"));
});
$(document).mousemove(function(e){
if(_move){
var x = e.pageX-_x;
var y = e.pageY-_y;
var wx = $(window).width()-$('.live-haruna-ctnr').width();
var dy = $(document).height()-$('.live-haruna-ctnr').height();
if(x>=0&&x<=wx&&y>0&&y<=dy){
$(".live-haruna-ctnr").css({
top:y,
left:x
});
ismove = true;
}
}
}).mouseup(function(){
_move = false;
});
//点击说话
$("#live2d").click(function(){
var msgs = ["你要干嘛呀?","鼠…鼠标放错地方了!","喵喵喵?","萝莉控是什么呀?","怕怕","你看到我的小熊了吗"];
var i = Math.floor(Math.random() * msgs.length);
showMessage(msgs[i]);
});
//移除事件监听
observer.disconnect();
document.removeEventListener("DOMSubtreeModified", changedHandler, false);
console.log('没穿衣服的2233替换完成');
}
if(Date.now() - ts >= 30 * 1000){
flag = false;
observer.disconnect();
document.removeEventListener("DOMSubtreeModified", changedHandler, false);
console.log('超时');
}
};
// 检查 MutationObserver 浏览器兼容
var MutationObserver = window.MutationObserver ||
window.WebKitMutationObserver ||
window.MozMutationObserver;
if (MutationObserver) {
// MutationObserver 配置
var MutationObserverConfig = {
// 监听子节点
childList: true,
// 监听 href 属性
attributes: true,
// 监听整棵树
subtree: true
};
// 监听器
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
// 处理 变化的 DOM
changedHandler(mutation.target);
// 处理 新增的 DOM
if (mutation.addedNodes) {
mutation.addedNodes.forEach(changedHandler);
}
// 删除的 DOM 无需处理 (mutation.removedNodes)
});
});
return function () {
// 开始监听
observer.observe(document.body, MutationObserverConfig);
};
} else if (document.body.addEventListener) {
// addEventListener 和 Mutation events 都是 IE 9 以上才支持
var bindMutationEvents = function (eventName) {
document.body.addEventListener(eventName, function (e) {
changedHandler(e.target);
});
};
var binded = false;
return function () {
if (binded) {
return;
}
binded = true;
bindMutationEvents('DOMSubtreeModified');
bindMutationEvents('DOMNodeInserted');
};
} else {
// IE 8- 就不管了
return function () {
console.log('MutationObserver not support!');
};
}
})();
observeDOMChanges();
//封装一些方法
String.format = function(src){
if (arguments.length == 0) return null;
var args = Array.prototype.slice.call(arguments, 1);
return src.replace(/\{(\d+)\}/g, function(m, i){
return args[i];
});
};
function showMessage(a,b){
if(b === null) b = 10000;
$(".base-bubble,.speaking-bubble,.bubble-item").hide().stop();
$(".speaking-bubble").html(a);
$(".base-bubble,.speaking-bubble,.bubble-item").fadeTo("10",1);
$(".base-bubble,.speaking-bubble,.bubble-item").fadeOut(b);
}
})();
@Caesar0220
Copy link

会玩你就多整点!

@Lius-ToGo
Copy link

会玩你就多整点!牛逼啊!

@wlt233
Copy link

wlt233 commented Apr 12, 2020

有点好奇模型是从哪里整来的

@RitaRossweiss
Copy link

技术宅为所欲为.png

@wangkaiyu2333
Copy link

大佬在吗 现在插件不能生效 好像是你的服务器出了问题

@journey-ad
Copy link
Author

大佬在吗 现在插件不能生效 好像是你的服务器出了问题

已恢复

@Izumi-Koishi
Copy link

?在哪?我怎么没看到?

@Izumi-Koishi
Copy link

把啥给替换了?

@PencilMR
Copy link

哈哈,这波可以

@ttop5
Copy link

ttop5 commented Jul 31, 2020

你好骚啊

@wudiansi
Copy link

好大的胆子 敢开233娘的车

@feng43
Copy link

feng43 commented Jul 31, 2020

大佬强无敌

@novice2194
Copy link

直呼会玩

@erdaikakaluote
Copy link

直呼会玩

@mashirozx
Copy link

6

@qhl123456
Copy link

怎么用到油猴里呢

@journey-ad
Copy link
Author

@287976255
Copy link

只有pc端的网页有挂件吗,手机版是不是没有

@erdaikakaluote
Copy link

erdaikakaluote commented Nov 20, 2020 via email

@erdaikakaluote
Copy link

erdaikakaluote commented Nov 20, 2020 via email

@lbr77
Copy link

lbr77 commented Feb 19, 2021

牛啊

@ChenYFan
Copy link

图片把我看喷了

@zhu-ty
Copy link

zhu-ty commented Mar 24, 2021

2233娘挂件是什么东西……我咋没见过呢

@Spencer-WmlonS
Copy link

失效了呀

@journey-ad
Copy link
Author

失效了呀

已修复

@pendave
Copy link

pendave commented May 2, 2021

看到2233娘了,第一次回知道有这么个玩意儿

@luotianyiismywife
Copy link

好耶,可以对着冲么[doge]

@luotianyiismywife
Copy link

嘉门

@ilovemiku14
Copy link

6b

@ottocsb
Copy link

ottocsb commented May 5, 2022

好像失效了,很久没看电脑端直播打开发现失效了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment