Add line counter, rewrite positioning code and support real edge dodging, track number of grabbed strings in reader, don't grab from distance text nodes
This commit is contained in:
1 parent
ba41a30e1a
commit
d9978c097d
4 files changed
+79
-77
No files matched your search
+1
-1
@@ -134,7 +134,7 @@ function defaults()
|
|||||||
kind: "combobox",
|
kind: "combobox",
|
||||||
options: ["Top left", "Top right", "Bottom left", "Bottom right", "Top auto"],
|
options: ["Top left", "Top right", "Bottom left", "Bottom right", "Top auto"],
|
||||||
default: 0,
|
default: 0,
|
||||||
label: "Popup positioning corner (note: \"bottom ___\" and \"top auto\" have problems due to web technology being a bad fit for mouseover dictionaries)"
|
label: "Popup positioning corner (note: \"top auto\" has problems due to web technology being a bad fit for mouseover dictionaries)"
|
||||||
});
|
});
|
||||||
|
|
||||||
// theme
|
// theme
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ p
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body lang="ja">
|
<body lang="ja">
|
||||||
|
<p>Strings grabbed: <span id="linecount">0</span></p>
|
||||||
<p><i>This page grabs from the clipboard automatically if it contains Japanese text. If this page is not opened, Nazeka will never access the clipboard.</i></p>
|
<p><i>This page grabs from the clipboard automatically if it contains Japanese text. If this page is not opened, Nazeka will never access the clipboard.</i></p>
|
||||||
<p><i>Use the context menu (right click the page) to toggle Nazeka.</i></p>
|
<p><i>Use the context menu (right click the page) to toggle Nazeka.</i></p>
|
||||||
<div style="position:absolute;visibility:hidden"><textarea id="nazeka-paste-target"></textarea></div>
|
<div style="position:absolute;visibility:hidden"><textarea id="nazeka-paste-target"></textarea></div>
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ function update(text)
|
|||||||
target.insertBefore(newnode, document.body.firstChild);
|
target.insertBefore(newnode, document.body.firstChild);
|
||||||
else
|
else
|
||||||
target.appendChild(newnode);
|
target.appendChild(newnode);
|
||||||
|
|
||||||
|
document.getElementById("linecount").innerText = parseInt(document.getElementById("linecount").innerText)+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let text_previous = "";
|
let text_previous = "";
|
||||||
|
|||||||
+75
-76
@@ -225,100 +225,79 @@ function display_div(middle, x, y)
|
|||||||
if(!settings.fixedwidthpositioning)
|
if(!settings.fixedwidthpositioning)
|
||||||
mywidth = outer.offsetWidth*settings.scale;
|
mywidth = outer.offsetWidth*settings.scale;
|
||||||
|
|
||||||
|
let corner = settings.corner;
|
||||||
|
|
||||||
if(settings.sticky && platform != "android" && get_doc().body.getElementsByClassName("nazeka_mining_ui").length == 0)
|
if(settings.sticky && platform != "android" && get_doc().body.getElementsByClassName("nazeka_mining_ui").length == 0)
|
||||||
set_sticky_styles(outer);
|
set_sticky_styles(outer);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let corner = settings.corner;
|
|
||||||
|
|
||||||
let buffer = 25;
|
let buffer = settings.xoffset+5;
|
||||||
if(corner != 1 && corner != 3)
|
|
||||||
|
if(mywidth+buffer*2 < mydoc.documentElement.getBoundingClientRect().width)
|
||||||
{
|
{
|
||||||
let pretend_doc_width = Math.max(mywidth, mydoc.defaultView.innerWidth) + mydoc.defaultView.scrollX;
|
if((corner == 0 || corner == 2) && newx+mywidth+buffer > mydoc.documentElement.getBoundingClientRect().right)
|
||||||
if(newx + mywidth > pretend_doc_width-buffer)
|
|
||||||
{
|
{
|
||||||
if(corner == 4)// && Math.abs(newx + mywidth - pretend_doc_width) > mywidth/2)
|
if(corner == 0)
|
||||||
corner = 1;
|
corner = 1;
|
||||||
|
else if(corner == 2)
|
||||||
|
corner = 3;
|
||||||
|
}
|
||||||
|
if((corner == 1 || corner == 3) && newx-mywidth-buffer < mydoc.documentElement.getBoundingClientRect().left)
|
||||||
|
{
|
||||||
|
if(corner == 1)
|
||||||
|
corner = 0;
|
||||||
|
else if(corner == 3)
|
||||||
|
corner = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(corner == 1 || corner == 3)
|
||||||
|
{
|
||||||
|
newx -= mywidth;
|
||||||
|
newx -= settings.xoffset;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
newx += settings.xoffset;
|
||||||
newx -= (newx + mywidth - pretend_doc_width);
|
|
||||||
newx -= buffer;
|
|
||||||
if(newx < mydoc.defaultView.scrollX)
|
|
||||||
newx = mydoc.defaultView.scrollX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(corner == 1 || corner == 3) // don't use else here, we might get here because of "corner = 1" a few lines above
|
|
||||||
{
|
|
||||||
let pretend_doc_width = Math.max(mywidth, mydoc.defaultView.innerWidth) - mydoc.defaultView.scrollX;
|
|
||||||
newx = mydoc.defaultView.innerWidth - newx;
|
|
||||||
if(newx + mywidth > pretend_doc_width-buffer)
|
|
||||||
{
|
|
||||||
newx += (newx + mywidth - pretend_doc_width);
|
|
||||||
newx += buffer;
|
|
||||||
// this is wrong but it can't be fixed without invoking cthulhu
|
|
||||||
if(newx > mydoc.defaultView.innerWidth-mydoc.defaultView.scrollX-mywidth-buffer+5)
|
|
||||||
newx = mydoc.defaultView.innerWidth-mydoc.defaultView.scrollX-mywidth-buffer+5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(corner == 2 || corner == 3)
|
if(corner == 2 || corner == 3)
|
||||||
{
|
newy = newy - outer.getBoundingClientRect().height;
|
||||||
newy = mydoc.defaultView.innerHeight - newy;
|
|
||||||
if(newy < 0)
|
|
||||||
newy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(corner == 3)
|
|
||||||
{
|
|
||||||
outer.style.top = "unset";
|
|
||||||
outer.style.bottom = (newy+settings.yoffset)+"px";
|
|
||||||
outer.style.right = (newx-settings.xoffset)+"px";
|
|
||||||
outer.style.left = "unset";
|
|
||||||
outer.style.marginRight = "unset";
|
|
||||||
outer.style.marginLeft = "unset";
|
|
||||||
}
|
|
||||||
else if(corner == 2)
|
|
||||||
{
|
|
||||||
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
|
||||||
outer.style.top = "0px";
|
|
||||||
outer.style.left = "0px";
|
|
||||||
let width = outer.offsetWidth;
|
|
||||||
|
|
||||||
outer.style.top = "unset";
|
|
||||||
outer.style.bottom = (newy+settings.yoffset)+"px";
|
|
||||||
outer.style.right = "unset";
|
|
||||||
outer.style.left = (newx+settings.xoffset)+"px";
|
|
||||||
outer.style.marginRight = "unset";
|
|
||||||
outer.style.marginLeft = "unset";
|
|
||||||
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
|
||||||
outer.style.width = (width)+"px";
|
|
||||||
}
|
|
||||||
else if(corner == 1)
|
|
||||||
{
|
|
||||||
outer.style.top = (newy+settings.yoffset)+"px";
|
|
||||||
outer.style.bottom = "unset";
|
|
||||||
outer.style.right = (newx-settings.xoffset)+"px";
|
|
||||||
outer.style.left = "unset";
|
|
||||||
outer.style.marginRight = "unset";
|
|
||||||
outer.style.marginLeft = "unset";
|
|
||||||
}
|
|
||||||
else // 0 or invalid
|
|
||||||
{
|
|
||||||
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
||||||
outer.style.top = "0px";
|
outer.style.top = "0px";
|
||||||
outer.style.left = "0px";
|
outer.style.left = "0px";
|
||||||
let width = outer.offsetWidth;
|
let width = outer.offsetWidth;
|
||||||
|
//
|
||||||
|
|
||||||
|
if(corner == 3 || corner == 2)
|
||||||
|
outer.style.top = (newy-settings.yoffset)+"px";
|
||||||
|
else
|
||||||
outer.style.top = (newy+settings.yoffset)+"px";
|
outer.style.top = (newy+settings.yoffset)+"px";
|
||||||
outer.style.bottom = "unset";
|
outer.style.bottom = "unset";
|
||||||
outer.style.right = "unset";
|
outer.style.right = "unset";
|
||||||
outer.style.left = (newx+settings.xoffset)+"px";
|
outer.style.left = (newx)+"px";
|
||||||
outer.style.marginRight = "unset";
|
outer.style.marginRight = "unset";
|
||||||
outer.style.marginLeft = "unset";
|
outer.style.marginLeft = "unset";
|
||||||
|
|
||||||
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
// fixes an absolute positioning """feature""" that doesn't work properly with very wide pages (e.g. pages of left-to-right vertical text)
|
||||||
outer.style.width = (width)+"px";
|
outer.style.width = (width)+"px";
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let localrect = outer.getBoundingClientRect();
|
||||||
|
|
||||||
|
if(localrect.bottom-5 > window.innerHeight)
|
||||||
|
{
|
||||||
|
newy -= localrect.bottom-5 - window.innerHeight;
|
||||||
|
outer.style.top = (newy)+"px";
|
||||||
|
}
|
||||||
|
|
||||||
|
localrect = outer.getBoundingClientRect();
|
||||||
|
|
||||||
|
if(localrect.top-5 < 0)
|
||||||
|
{
|
||||||
|
newy -= localrect.top-5;
|
||||||
|
outer.style.top = (newy)+"px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1332,6 +1311,7 @@ function update(event)
|
|||||||
//console.log("searching for text");
|
//console.log("searching for text");
|
||||||
let textNode;
|
let textNode;
|
||||||
let offset;
|
let offset;
|
||||||
|
let hitrect;
|
||||||
|
|
||||||
let nodeResetList = [];
|
let nodeResetList = [];
|
||||||
let nodeResetSeen = new Set();
|
let nodeResetSeen = new Set();
|
||||||
@@ -1364,20 +1344,41 @@ function update(event)
|
|||||||
yoffset = searchoffset;
|
yoffset = searchoffset;
|
||||||
else
|
else
|
||||||
xoffset = searchoffset;
|
xoffset = searchoffset;
|
||||||
let range = undefined;
|
|
||||||
if (document.caretPositionFromPoint)
|
if (document.caretPositionFromPoint)
|
||||||
range = document.caretPositionFromPoint(x+xoffset, y+yoffset);
|
{
|
||||||
|
let caretdata = document.caretPositionFromPoint(x+xoffset, y+yoffset);
|
||||||
|
if(caretdata)
|
||||||
|
{
|
||||||
|
textNode = caretdata.offsetNode;
|
||||||
|
offset = caretdata.offset;
|
||||||
|
|
||||||
|
let range = document.createRange();
|
||||||
|
range.selectNode(textNode);
|
||||||
|
hitrect = range.getBoundingClientRect();
|
||||||
|
range.detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (document.caretRangeFromPoint)
|
else if (document.caretRangeFromPoint)
|
||||||
range = document.caretRangeFromPoint(x+xoffset, y+yoffset);
|
{
|
||||||
|
let range = document.caretRangeFromPoint(x+xoffset, y+yoffset);
|
||||||
if(range)
|
if(range)
|
||||||
{
|
{
|
||||||
textNode = range.offsetNode;
|
textNode = range.startContainer;
|
||||||
offset = range.offset;
|
offset = range.startOffset;
|
||||||
|
hitrect = range.getBoundingClientRect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(ele && !ele.contains(textNode) && platform != "android" && !settings.sticky) // sticky mode and android need to break out on parent detection
|
if(ele && !ele.contains(textNode) && platform != "android" && !settings.sticky) // sticky mode and android need to break out on parent detection
|
||||||
{
|
{
|
||||||
textNode = undefined;
|
textNode = undefined;
|
||||||
offset = undefined;
|
offset = undefined;
|
||||||
|
hitrect = undefined;
|
||||||
|
}
|
||||||
|
if(x > hitrect.right+5 || x < hitrect.left-5 || y > hitrect.bottom+5 || y < hitrect.top-5)
|
||||||
|
{
|
||||||
|
textNode = undefined;
|
||||||
|
offset = undefined;
|
||||||
|
hitrect = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1641,8 +1642,6 @@ function keyuntest(event)
|
|||||||
shift_down = false;
|
shift_down = false;
|
||||||
if(event.key == "Control")
|
if(event.key == "Control")
|
||||||
ctrl_down = false;
|
ctrl_down = false;
|
||||||
if(event.key == "Alt")
|
|
||||||
alt_down = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user