Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Kawaii desu neeeeee
- // @namespace https://github.com/Retarded-Skid/
- // @version 0.2
- // @description add a waifu to your browser
- // @author skid
- // @match *://*/*
- // @grant none
- // ==/UserScript==
- (function() {
- var liveLoaded = true;
- var localhost = false;
- var prefix = localhost ? "" : "https://retarded-skid.github.io/dumb/";
- function loadLive2D() {
- var scriptL2D = document.createElement('script');
- scriptL2D.type = "text/javascript";
- scriptL2D.async = true;
- scriptL2D.src = prefix + "live2dw/lib/L2Dwidget.min.js";
- document.body.appendChild(scriptL2D);
- }
- function waitForElement(){
- if(typeof L2Dwidget !== "undefined"){
- var size = 100;
- init("right", size, size);
- } else {
- setTimeout(waitForElement, 10);
- }
- }
- function init(align, width, height) {
- L2Dwidget.init({
- "pluginRootPath": prefix + "live2dw/",
- "pluginJsPath":"lib/",
- "pluginModelPath":"assets/",
- "tagMode":false,
- "debug":false,
- "model":{
- "jsonPath": prefix + "live2dw/assets/unitychan.model.json"
- },
- "display":{
- "position": align,
- "width": width,
- "height": height,
- },
- "mobile":{
- "show":true
- },
- "log":false
- });
- }
- //
- function setupDragging() {
- var elm = document.getElementById("live2dcanvas");
- if (elm != null) {
- var dx = 0, dy = 0, lastX = 0, lastY = 0;
- elm.style.pointerEvents = "all";
- elm.style.width = null;
- elm.style.height = null;
- elm.onmousedown = onClick;
- elm.onmouseover = onHover;
- function onHover(e) {
- // TODO: Change pointer
- }
- function onClick(e) {
- e = e || window.event;
- e.preventDefault();
- lastX = e.clientX;
- lastY = e.clientY;
- document.onmouseup = onRelease;
- document.onmousemove = onDrag;
- }
- function onDrag(e) {
- e = e || window.event;
- e.preventDefault();
- dx = lastX - e.clientX;
- dy = lastY - e.clientY;
- lastX = e.clientX;
- lastY = e.clientY;
- elm.style.top = (elm.offsetTop - dy) + "px";
- elm.style.left = (elm.offsetLeft - dx) + "px";
- }
- function onRelease() {
- document.onmouseup = null;
- document.onmousemove = null;
- }
- } else {
- setTimeout(setupDragging, 10);
- }
- }
- //
- // TODO: Figure out how to prevent duplicate executions when viewing embedded items
- loadLive2D();
- waitForElement();
- setupDragging();
- //
- })();
Advertisement
Add Comment
Please, Sign In to add comment