// ==UserScript== // @name dA_dragFullscreen // @namespace http://phi.pf-control.de/userscripts/dA_dragFullscreen // @version 1.3 // @description drag too large image in fullscreen // @author Dediggefedde // @match https://www.deviantart.com/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.12.1/jquery.min.js // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js // @grant GM.setValue // @grant GM.getValue // @downloadURL https://update.greasyfork.icu/scripts/419629/dA_dragFullscreen.user.js // @updateURL https://update.greasyfork.icu/scripts/419629/dA_dragFullscreen.meta.js // ==/UserScript== /* globals $*/ /* jshint esnext:true */ (function() { 'use strict'; /* //works, but too much drag on very large images function addDragger(){ var el=$("div.ReactModal__Content--after-open img").not("[dA_dragFullscreen]").attr("dA_dragFullscreen",1).draggable(); if(el.length>0)console.log(el); } setInterval(addDragger,1000); */ //imgGear copied from inkscape "render gear", slightly adjusted let imgGear=' '; let tracking=false; let trackingMoved=false; let copyImg, img, highRec; let diag; let cImgW,cImgH,imgW,imgH, winW,winH; let userSet={ dragRequired:false, opacityPrev:0, opacityHigh:0, marginPrev:0.02 }; function leaveTracking(){ tracking=false; copyImg.hide(); highRec.hide(); } function moveToXY(tx,ty){ imgW=img.width(); imgH=img.height(); let maxOffX=imgW-winW; let maxOffY=imgH-winH; let highw=winW/imgW*cImgW; let highh=winH/imgH*cImgH; let cImgOff=copyImg.offset(); let x = tx-cImgOff.left-highw/2; let y = ty-cImgOff.top-highh/2; if(x<0)x=0; else if(x>cImgW-highw)x=cImgW-highw; if(y<0)y=0; else if(y>cImgH-highh)y=cImgH-highh; if(highw>cImgW)x=-(highw-cImgW)/2; if(highh>cImgH)y=-(highh-cImgH)/2; highRec.css({width:highw+"px",height:highh+"px",top: cImgOff.top+y+"px", left: cImgOff.left+x+"px"}); let scrollX=x/(cImgW-highw)*maxOffX; let scrollY=y/(cImgH-highh)*maxOffY; $("div.ReactModal__Content--after-open").parent().scrollLeft(scrollX).scrollTop(scrollY); } function resizePreview(){ winW=window.innerWidth; winH=window.innerHeight; let ratImg=img.width()/img.height(); let ratWin=winW/winH; copyImg.css({ position:"fixed",'max-height':winH*(1-2*userSet.marginPrev)+"px",'max-width':winW*(1-2*userSet.marginPrev)+"px",top:winH*userSet.marginPrev+"px",left:winW*userSet.marginPrev+"px", opacity:userSet.opacityPrev,display:"none",cursor:"move",'z-index':2 }); if(ratImg>ratWin){//wider than window copyImg.css({top:(winH-winW*(1-2*userSet.marginPrev)/ratImg)/2+"px"}); }else{ copyImg.css({left:(winW-winH*(1-2*userSet.marginPrev)*ratImg)/2+"px"}); } cImgW=copyImg.width(); cImgH=copyImg.height(); highRec.css({ opacity:userSet.opacityHigh,position:"fixed",border:"2px solid #475c4daa",'box-shadow':"0px 0px 10px white inset",display:"none",'box-sizing':"border-box",'z-index':3 }); } function addDragger(){ let el=$("div.ReactModal__Content[role=dialog]>div>img").not("[dA_dragFullscreen]").attr("dA_dragFullscreen",1).attr("draggable","false"); if(el.length>0){ img=el; winW=window.innerWidth; winH=window.innerHeight; copyImg=img.clone().attr("dA_dragFullscreen",2).insertAfter(img); highRec=$("
").insertAfter(img); resizePreview(); $(document).on("mouseleave",function (ev){ leaveTracking(); }); img.on("mousedown",function(ev){ imgW=img.width(); imgH=img.height(); if(imgW>winW||imgH>winH){ tracking=true; } trackingMoved=false; ev.preventDefault(); ev.stopPropagation(); }).on("mouseup",function(ev){ leaveTracking() ev.preventDefault(); ev.stopPropagation(); }).on("click",function(ev){ if(trackingMoved){ ev.preventDefault(); ev.stopPropagation(); } }).on("mousemove",function(ev){ if(!tracking && userSet.dragRequired)return; if(!trackingMoved){ copyImg.show(); highRec.show(); } trackingMoved=true; moveToXY(ev.pageX,ev.pageY); }); copyImg.on("mousemove",function(ev){ if(!tracking && userSet.dragRequired)return; trackingMoved=true; moveToXY(ev.pageX,ev.pageY); }).on("mouseup",function(ev){ leaveTracking() ev.preventDefault(); ev.stopPropagation(); }); let but=$("
"+imgGear+"
"); let closebut=$("div.ReactModal__Content button"); but.css({ cursor:'pointer','z-index':99,position:"fixed",'background-color': "rgba(var(--L2-RGB),.8)",'border-radius': "50px",display: "flex",'align-items': "center",'justify-content': "center", top:parseInt(closebut.css("top"))+closebut.height()+20+"px",right:closebut.css("right"),height: "48px",width:closebut.css("width") }); closebut.parent().after(but); diag=$(`
`); document.body.append(diag); but.on("mouseup",function(ev){ ev.preventDefault(); ev.stopPropagation(); }).on("click",function(ev){ ev.preventDefault(); ev.stopPropagation(); diag.dialog({ modal: true, width:400, title:"dragFullscreen Settings", buttons: { 'OK': function () { userSet.dragRequired = $('input[name="dragRequired"]').prop("checked"); userSet.opacityPrev = $('input[name="previewOpacity"]').val()/100.0; userSet.opacityHigh= $('input[name="highOpacity"]').val()/100.0; userSet.marginPrev= $('input[name="previewMargin"]').val()/100.0; $(this).dialog('close'); GM.setValue("settings",JSON.stringify(userSet)); resizePreview(); }, 'Cancel': function () { $(this).dialog('close'); } } }); }); } } $("head").append( '' ); GM.getValue("settings","").then((val)=>{ if(val=="")return; userSet=JSON.parse(val); if(!userSet.hasOwnProperty("marginPrev"))userSet.marginPrev=0.1;//default, backwards compability to v1.1 }).finally(()=>{ setInterval(addDragger,1000); }); })();