LordPankake

weeb userscript

Sep 6th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Kawaii desu neeeeee
  3. // @namespace    https://github.com/Retarded-Skid/
  4. // @version      0.2
  5. // @description  add a waifu to your browser
  6. // @author       skid
  7. // @match        *://*/*
  8. // @grant        none
  9. // ==/UserScript==
  10. (function() {
  11. var liveLoaded = true;
  12. var localhost = false;
  13. var prefix = localhost ? "" : "https://retarded-skid.github.io/dumb/";
  14. function loadLive2D() {
  15.     var scriptL2D = document.createElement('script');
  16.     scriptL2D.type = "text/javascript";
  17.     scriptL2D.async = true;
  18.     scriptL2D.src = prefix + "live2dw/lib/L2Dwidget.min.js";
  19.     document.body.appendChild(scriptL2D);
  20. }
  21. function waitForElement(){
  22.     if(typeof L2Dwidget !== "undefined"){
  23.         var size = 100;
  24.         init("right", size, size);
  25.     } else {
  26.         setTimeout(waitForElement, 10);
  27.     }
  28. }
  29. function init(align, width, height) {
  30.     L2Dwidget.init({
  31.         "pluginRootPath": prefix + "live2dw/",
  32.         "pluginJsPath":"lib/",
  33.         "pluginModelPath":"assets/",
  34.         "tagMode":false,
  35.         "debug":false,
  36.         "model":{
  37.             "jsonPath": prefix + "live2dw/assets/unitychan.model.json"
  38.         },
  39.         "display":{
  40.             "position": align,
  41.             "width": width,
  42.             "height": height,
  43.         },
  44.         "mobile":{
  45.             "show":true
  46.         },
  47.         "log":false
  48.     });
  49. }
  50. //
  51. function setupDragging() {
  52.     var elm = document.getElementById("live2dcanvas");
  53.     if (elm != null) {
  54.         var dx = 0, dy = 0, lastX = 0, lastY = 0;
  55.         elm.style.pointerEvents = "all";
  56.         elm.style.width = null;
  57.         elm.style.height = null;
  58.         elm.onmousedown = onClick;
  59.         elm.onmouseover = onHover;
  60.         function onHover(e) {
  61.             // TODO: Change pointer
  62.         }
  63.         function onClick(e) {
  64.             e = e || window.event;
  65.             e.preventDefault();
  66.             lastX = e.clientX;
  67.             lastY = e.clientY;
  68.             document.onmouseup = onRelease;
  69.             document.onmousemove = onDrag;
  70.         }
  71.         function onDrag(e) {
  72.             e = e || window.event;
  73.             e.preventDefault();
  74.             dx = lastX - e.clientX;
  75.             dy = lastY - e.clientY;
  76.             lastX = e.clientX;
  77.             lastY = e.clientY;
  78.             elm.style.top = (elm.offsetTop - dy) + "px";
  79.             elm.style.left = (elm.offsetLeft - dx) + "px";
  80.         }
  81.         function onRelease() {
  82.             document.onmouseup = null;
  83.             document.onmousemove = null;
  84.         }
  85.     } else {
  86.         setTimeout(setupDragging, 10);
  87.     }
  88. }
  89. //
  90. // TODO: Figure out how to prevent duplicate executions when viewing embedded items
  91.     loadLive2D();
  92.     waitForElement();
  93.     setupDragging();
  94. //
  95. })();
Advertisement
Add Comment
Please, Sign In to add comment