讨论 » 创建请求

Adding cases

§
发布于:2023-12-13
编辑于:2023-12-13

case "account_rights":
switch(value){
case "owner":
case "tester":
show_element("top-bar-admin-link");
break;
}
break;


Can I make a script to add cases to this?
Like this

case "account_rights":
switch(value){
case "owner":
case "tester":
case "user1":
show_element("top-bar-admin-link");
break;
}
break;

This code is in a js file called items.js connected to my html

NotYou管理员
§
发布于:2023-12-13

Try this:

const arr = ['owner', 'tester', 'user1'];

switch (...) {
  case 'account_rights':
    if (value in arr) {
      show_element('top-bar-admin-link');
    }
    break;
}

And you can easily add items using arr.push method, like this:

arr.push('helloworld')
§
发布于:2023-12-13

Like This?

// ==UserScript==
// @name IdlePixel plug
// @namespace com.Ethan.idlepixelplug
// @version 1.0.0
// @description Upgrade the Game...
// @author Ethan
// @license MIT
// @match *://idle-pixel.com/login/play*
// @grant none
// @require https://greasyfork.runtimutd.eu.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// @require https://cdnjs.cloudflare.com/ajax/libs/anchorme/2.1.2/anchorme.min.js
// @require https://unpkg.com/react@17/umd/react.production.min.js
// @require https://unpkg.com/react-dom@17/umd/react-dom.production.min.js
// @require https://unpkg.com/@reduxjs/[email protected]/dist/redux-toolkit.umd.min.js
// @require https://unpkg.com/[email protected]/dist/react-redux.js
// @require https://greasyfork.runtimutd.eu.org/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==

(function() {
'use strict';

const arr = ['owner', 'tester', 'user1'];

switch (account_rights) {
case 'owner':
case 'tester':
case 'user1':
show_element('top-bar-admin-link');
break;
}

const plugin = new plugPlugin();
IdlePixelPlus.registerPlugin(plugin);

})();

It doesn't seem to be working

§
发布于:2023-12-14

This is the error

userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:22 Uncaught (in promise) ReferenceError: account_rights is not defined
at userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:22:5
at Object. (userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:35:3)
at St (:9:89)
at userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:1:89
at window.__f__lq5o5c2n.e5 (userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:1:317)
at St (:9:89)
at s (:72:214)
at :75:107
at g (:69:364)

§
发布于:2023-12-14
编辑于:2023-12-14

switch checks for
account_rights

Does var account_rights = '' exist?

no

therefore it breaks...

NotYou管理员
§
发布于:2023-12-15

Like This?

No, not like that. You wrote code incorrectly. Looks like you didn't want to figure out my code. Check your own code, man, there is supposed to be another switch case, that's why I wrote switch(...), so you could copy-paste your switch-case that was before.

§
发布于:2023-12-15

Sorry, I have limited experience in this and was looking for help.

So if I understood was it supposed to be like this?

/ ==UserScript==
// @name IdlePixel plug
// @namespace com.Ethan.idlepixelplug
// @version 1.0.9
// @description Upgrade the Game...
// @author Ethan
// @license MIT
// @match *://idle-pixel.com/login/play*
// @grant none
// @require https://greasyfork.runtimutd.eu.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// @require https://greasyfork.runtimutd.eu.org/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==

(function() {
'use strict';

const arr = ['owner', 'tester', 'ethanlar'];

switch (Items) {
case 'account_rights':
if (value in arr) {
show_element('top-bar-admin-link');
}
break;
}

const plugin = new IdlePixelPlus.plugPlugin();
IdlePixelPlus.registerPlugin(plugin);
})();


Or am I missing something cus I still get this error,

userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:2967 Uncaught (in promise) TypeError: IdlePixelPlus.plugPlugin is not a constructor
at userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:2967:16
at Object. (userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:2969:3)
at St (:9:89)
at userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:1:90
at window.__f__lq75hud9.tvh (userscript.html?name=IdlePixel-plug.user.js&id=4a39e9a0-e613-45a6-ab13-cce7b6e59ca5:1:318)
at St (:9:89)
at s (:72:214)
at :75:107
at g (:69:364)

If I'm missing something please let me know so I can understand how to resolve this.

NotYou管理员
§
发布于:2023-12-15

The error literally says what's the problem: TypeError: IdlePixelPlus.plugPlugin is not a constructor.

You are trying to make an instance of the class, but plugPlugin is not a constructor, so you can't create an instance.

And where is variable Items defined? Items is undefined, switch case never going to match in this situation.

Also, yes, code is more correct now.

§
发布于:2023-12-15

Sorry this is my first time making a plugin, can you explain it in simpler teams for me to understand, please

NotYou管理员
§
发布于:2023-12-16

Learn JavaScript first.

§
发布于:2023-12-16
编辑于:2023-12-16

Watch yt videos or go learn any programming language, or https://ko-fi.com/hacker09/commissions#buyShopCommissionModal

发布留言

登录以发布留言。