如何修复被黑版的waitForKeyElements中的无限循环? [英] How do I fix an infinite loop in a hacked version of waitForKeyElements?

查看:118
本文介绍了如何修复被黑版的waitForKeyElements中的无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司的网站使用 Metronic水平菜单管理面板,但是它是使用一个齿轮,而不是用户个人资料图片和名称.在Firefox 30之前的版本中,此Greasemonkey脚本可以运行,并且可以将我的个人资料"和注销"按钮移至用户个人资料/名称下,同时将我的日历",我的收件箱"和我的任务"保留在齿轮内图标下拉菜单.这是我的Greasemonkey代码:

My company's website uses the Metronic Horizontal Menu admin panel, but it's an older version that uses a Gear instead of the user profile picture and name. Before Firefox 30, this Greasemonkey script was working and would move the "My Profile" and "Log Out" buttons under the user profile/name, while keeping "My Calendar", "My Inbox", and "My Tasks" inside the gear icon dropdown. Here's my Greasemonkey code:

// ==UserScript==
// @name        Fix User Dropdown
// @description Fixes the user dropdown to match current version.
// @include     mywebsite.com
// @version     2.0.0
// @require         https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require         https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant               GM_addStyle
// @grant               GM.getValue
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.

waitForKeyElements (".topMenu1", addUserDropdown, true);

function addUserDropdown(jNode) {
  $('#greetingName').remove();
  var userSession = unsafeWindow.userSession;
  var userId = userSession.id;
  var firstName = userSession.firstName;
  var lastName = userSession.lastName;
  var fullName = firstName + ' ' + lastName;
  var accountId = userSession.accountId;

  $('.top-menu .nav').prepend(
        '<li class="dropdown dropdown-user dropdown-dark">' + 
            '<a data-close-others="true" data-hover="dropdown" data-toggle="dropdown" class="dropdown-toggle username username-hide-mobile floatRight" href="#" style="padding:10px;border-right:1px solid #000;margin:5px;">' + 
                fullName + 
            '</a>' + 
            '<ul id="userPersonalMenu" class="dropdown-menu dropdown-menu-default">' + 
                '<li>' + 
                    '<a href="/user/editor?id=' + userId + '&amp;accountId=' + accountId + '" id="greetingNameLink">' + 
                    '<i class="icon-settings"></i> My Profile </a>' + 
                '</li>' + 
                '<li>' + 
                    '<a href="/logout">' + 
                    '<i class="icon-key"></i> Log Out </a>' + 
                '</li>' + 
            '</ul>' + 
        '</li>');

  $('.dropdown-toggle').dropdownHover({});

  return null;
}

会发生这种情况:

它永远不会打印"CANCEL FOUND",因为调用栈仍然可以解决,所以就我所担心的,它违反了逻辑.然后,它会从右到左再从上到下在屏幕上无限绘制用户的名称(在示例中为"Nick").

It never ever prints "CANCEL FOUND", which defies logic as far as I'm concerned since the call stack should still resolve. It then proceeds to draw the user's name ("Nick" in the example) infinitely across the screen from right-to-left and then top-to-bottom.

我希望将bWaitOnce设置为true可以解决此问题,但是没有骰子.

I was hoping that setting bWaitOnce to true would fix this, but no dice.

推荐答案

我添加了:

// @require https://raw.githubusercontent.com/CWSpear/bootstrap-hover-dropdown/master/bootstrap-hover-dropdown.js

在我的用户脚本顶部以获取最新版本的悬停下拉菜单,并且可以正常工作!

To the top of my user script to fetch the most recent version of the hover dropdown and it worked!

故事的故事,检查您的用户脚本使用了哪些页面依赖项,并确保它们与* Monkey兼容.

Moral of the story, check which page dependencies your user script uses and make sure they are compatible with *Monkey.

这篇关于如何修复被黑版的waitForKeyElements中的无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆