Javascript 在Chromium扩展的小部件中滚动到

Javascript 在Chromium扩展的小部件中滚动到,javascript,google-chrome,Javascript,Google Chrome,我试图修改一个chrome扩展,它在leo.org(dictionary)上查找突出显示的文本,并在实际窗口()内的小部件中显示结果。 我已经设法通过修改html部分来增加小部件的大小。此外,我希望在开始时将小部件滚动到特定位置,这样我就不必每次使用小部件时都在小部件内部手动滚动。我已经尝试过类似于tmpwidget.ScrollTo(100100);或widget.ScrollTo(100100) 但是我一点结果也没有。 以下是分机的代码: var org; (function (org) {

我试图修改一个chrome扩展,它在leo.org(dictionary)上查找突出显示的文本,并在实际窗口()内的小部件中显示结果。 我已经设法通过修改html部分来增加小部件的大小。此外,我希望在开始时将小部件滚动到特定位置,这样我就不必每次使用小部件时都在小部件内部手动滚动。我已经尝试过类似于
tmpwidget.ScrollTo(100100);或widget.ScrollTo(100100)
但是我一点结果也没有。
以下是分机的代码:

var org;
(function (org) {
    var leo;
    (function (leo) {
        var dict;
        (function (dict) {
            var Widget = (function () {
                function Widget(settings, widgetID) {
                    if (widgetID === void 0) { widgetID = "__$$leodictwidget$$__"; }
                    var _this = this;
                    this.widgetID = widgetID;
                    this.settings = settings;
                    this.boundMoveObject = null;
                    window.addEventListener("mouseup", function (e) {
                        if (_this.widget()) {
                            if (_this.boundMoveObject) {
                                window.removeEventListener("mousemove", _this.boundMoveObject, true);
                                _this.boundMoveObject = null;
                            }
                            var query = window.getSelection().toString().trim();
                            if (query.length > 1) {
                                (_this.widget().childNodes[1]).src = _this.buildUrl(query);
                            }
                        }
                    }, false);
                    window.addEventListener("keydown", function (e) {
                        var specialKeyPressed = false;
                        switch (settings.shortcutSpecialKey) {
                            case "alt":
                                specialKeyPressed = e.altKey;
                                break;
                            case "shift":
                                specialKeyPressed = e.shiftKey;
                                break;
                            case "ctrl":
                                specialKeyPressed = e.ctrlKey;
                                break;
                            // Command Key on Mac
                            case "cmd-key":
                                var isMac = navigator.platform.toUpperCase().indexOf('MAC') != -1;
                                specialKeyPressed = e.metaKey && isMac;
                                break;
                        }
                        if (specialKeyPressed && e.keyCode == parseInt(settings.shortcutKey, 10)) {
                            if (_this.widget()) {
                                _this.hide();
                            }
                            else {
                                var query = window.getSelection().toString().trim();
                                _this.show(_this.buildUrl(query));
                            }
                        }
                    }, false);
                }
                Widget.prototype.widget = function () {
                    return document.getElementById(this.widgetID);
                };
                Widget.prototype.hide = function (e) {
                    if (typeof e !== "undefined") {
                        e.preventDefault();
                    }
                    if (this.widget()) {
                        this.widget().parentNode.removeChild(this.widget());
                    }
                };
                Widget.prototype.initWidgetMove = function (e) {
                    this.offX = e.clientX - this.widget().offsetLeft;
                    this.offY = e.clientY - this.widget().offsetTop;
                    this.boundMoveObject = this.widgetMove.bind(this);
                    window.addEventListener("mousemove", this.boundMoveObject, true);
                };
                Widget.prototype.widgetMove = function (e) {
                    if (this.widget()) {
                        this.widget().style.left = (e.clientX - this.offX) + "px";
                        this.widget().style.top = (e.clientY - this.offY) + "px";
                    }
                };
                Widget.prototype.buildUrl = function (query) {
                    var url = "https://pda.leo.org/" + this.settings.language + "/";
                    if (query.length > 1)
                        url += encodeURIComponent(query);
                    return url;
                };
                Widget.prototype.show = function (url) {
                    if (this.widget()) {
                        return;
                    }
                    var tmpwidget = document.createElement('div');
                    tmpwidget.setAttribute('id', this.widgetID);
                    tmpwidget.setAttribute('style', 'position:fixed; right:10px; top:10px; width:340px; height:520px; border:0; z-index:2147483647; box-shadow: -5px 5px 5px #CCC;');
                    var html = "<div style='width:100%; height: 20px; background-color:rgb(66, 185, 66); text-align:right; cursor: pointer; -webkit-touch-callout: none; -webkit-user-select: none;";
                    html += "user-select: none; font-family: Arial, Verdana, sans-serif;padding:0;'>";
                    html += "<div style='float:right; background:#605F61; display:block; height:100%; padding: 0 3px; margin:0;line-height:0px;text-align:center;'>";
                    html += "<a style='text-decoration:none;color:#fff; display:block; font-size:25px; font-weight:bold; margin-top:8px;' href='#'>x</a></div></div>";
                    html += "<iframe style='width:100%; height:500px; border:0;' src='" + url + "'></iframe>";
                    html += "</div>";
                    tmpwidget.innerHTML = html;
                    document.body.appendChild(tmpwidget);
                    var dragborder = this.widget().childNodes[0];
                    dragborder.addEventListener("mousedown", this.initWidgetMove.bind(this), false);
                    var hidebtn = this.widget().getElementsByTagName("a")[0];
                    hidebtn.addEventListener("click", this.hide.bind(this), false);
                };
                return Widget;
            }());
            dict.Widget = Widget;
        })(dict = leo.dict || (leo.dict = {}));
    })(leo = org.leo || (org.leo = {}));
})(org || (org = {}));
/// <reference path="leodictwidget.ts" />
var widget = null;
var chrome;
chrome.runtime.sendMessage({ "action": "init" }, function (settings) {
    widget = new org.leo.dict.Widget(settings);
});
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    if (request.action == "launch-from-contextmenu") {
        widget.show(widget.buildUrl(request.selectionText));
    }
});
var组织;
(职能(组织){
利奥;
(功能(leo){
var-dict;
(功能(dict){
var小部件=(函数(){
功能小部件(设置、widgetID){
如果(widgetID==void 0){widgetID=“\uuuu$$leodictwidget$$\uuuuz”}
var_this=这个;
this.widgetID=widgetID;
this.settings=设置;
this.boundMoveObject=null;
window.addEventListener(“mouseup”,函数(e){
如果(_this.widget()){
if(_this.boundMoveObject){
window.removeEventListener(“mousemove”,\u this.boundMoveObject,true);
_this.boundMoveObject=null;
}
var query=window.getSelection().toString().trim();
如果(query.length>1){
(_this.widget().childNodes[1]).src=_this.buildUrl(查询);
}
}
},假);
window.addEventListener(“向下键”,函数(e){
var specialKeyPressed=false;
开关(设置。shortcutSpecialKey){
案例“alt”:
specialKeyPressed=e.altKey;
打破
案例“移位”:
specialKeyPressed=e.shiftKey;
打破
案例“ctrl”:
specialKeyPressed=e.ctrlKey;
打破
//Mac上的命令键
案例“cmd key”:
var isMac=navigator.platform.toUpperCase().indexOf('MAC')!=-1;
specialKeyPressed=e.metaKey&&isMac;
打破
}
如果(specialKeyPressed&&e.keyCode==parseInt(settings.shortcutKey,10)){
如果(_this.widget()){
_this.hide();
}
否则{
var query=window.getSelection().toString().trim();
_this.show(_this.buildUrl(查询));
}
}
},假);
}
Widget.prototype.Widget=函数(){
return document.getElementById(this.widgetID);
};
Widget.prototype.hide=函数(e){
如果(类型e!=“未定义”){
e、 预防默认值();
}
if(this.widget()){
this.widget().parentNode.removeChild(this.widget());
}
};
Widget.prototype.initWidgetMove=函数(e){
this.offX=e.clientX-this.widget().offsetLeft;
this.offY=e.clientY-this.widget().offsetTop;
this.boundMoveObject=this.widgetMove.bind(this);
window.addEventListener(“mousemove”,this.boundMoveObject,true);
};
Widget.prototype.widgetMove=函数(e){
if(this.widget()){
this.widget().style.left=(e.clientX-this.offX)+“px”;
this.widget().style.top=(e.clientY-this.offY)+“px”;
}
};
Widget.prototype.buildUrl=函数(查询){
变量url=”https://pda.leo.org/“+this.settings.language+”/”;
如果(query.length>1)
url+=encodeURIComponent(查询);
返回url;
};
Widget.prototype.show=函数(url){
if(this.widget()){
返回;
}
var tmpwidget=document.createElement('div');
tmpwidget.setAttribute('id',this.widgetID);
setAttribute('style','position:fixed;right:10px;top:10px;width:340px;height:520px;border:0;z-index:2147483647;方框阴影:-5px 5px#CCC;');
var html=“”;
html+=“”;
html+=“”;
html+=“”;
html+=“”;
tmpwidget.innerHTML=html;
document.body.appendChild(tmpwidget);
var dragborder=this.widget().childNodes[0];
dragborder.addEventListener(“mousedown”,this.initWidgetMove.bind(this),false);
var hidebtn=this.widget().getElementsByTagName(“a”)[0];
hidebtn.addEventListener(“单击”,this.hide.bind(this),false);
};
返回控件;
}());
dict.Widget=小部件;
})(dict=leo.dict | |(leo.dict={}));
})(leo=org.leo | |(org.leo={}));
})(org | |(org={}));
/// 
var=null;
var铬;
铬