以编程性评论和删除JavaScript功能

发布于 2025-02-08 16:43:31 字数 1743 浏览 1 评论 0原文

我有一个问题。我有这个逻辑:我有一个 javascript 文件,其中包含条件**如果** x = 0 load ** index.html ** else load ** index1.html* *。现在, index.html index1.html 是相同的,并且两个负载均相同的 javascript 文件,该文件包含一个应为条件<代码> x = 0 将用户带到应用程序,但需要限制x = 1时的某些操作。我只是想知道是否可能在决定采用这种方法或完全改变我需要做的事情的逻辑之前是否有可能。还有另一种方法,创建两个版本的 javaScript 文件,但是它将代表大量重复的文件,因为该评论和不受调的功能在应用程序上的多个位置中都存在,并且它是我认为,一个 MVC 项目比包含函数本身的文件要复制更多。

这个想法是,我将为一个计划提供两个计划,即免费计划和a pro计划。它们之间的独特区别是对某些功能的限制。因此,我拥有此功能:

if(userActive.isPro){
                    var payActive = JSON.parse(localStorage.getItem("payActive"));
                    if(payActive){
                        if(parseInt(payActive.status) === 1){
                            window.location.href= '../app/index.html';
                            
                        }
                    }
                    
                else{
                    window.location.href= '../app/index1.html';
                }

            }

这是使每个计划有所不同的功能。

function openAddPopup() {
    //check first if user is PRO Copy
    const userStatus = localStorage.getItem("userKind");
    const user = userStatus;
    if (user) {
        app.router.load('contactEdit', { 'isFavorite': state.isFavorite });
    } else {
        alert("You can only add 3 elements on the free version");
    }
}

对于 Pro Plan ,我需要执行该应用程序的完整版本,对于免费计划然后是受限版本。

因此,是否可以将 javascript 函数附加到 index.html index1.html 的情况下,要进行第二次,但是,如果 Pro Plan ,第一个?

I have a question. I have this logic in mind: I got a JavaScript file which contains a condition **if** x = 0 load **index.html** else load **index1.html**. Now, index.html and index1.html are identical and both loads the same JavaScript file which contains a function which should, for the condition x = 0 take the user to the app but need to restrict some actions when x = 1. I'm just trying to know if it is even possible before I decide if I take this approach or completely change the logic of what I need to do. There is another way, creating two versions of the JavaScript file, but it would represent a significant amount of duplicated files as this commented and uncommented functions are present in more than one place on the app and as it is an MVC project I would have, I think, to duplicate more than the file which contains the function itself.

The idea is that I'm going to serve an app with two plans, a FREE plan and a PRO plan. The unique difference between them is a restriction on certain functionalities. So I have this function:

if(userActive.isPro){
                    var payActive = JSON.parse(localStorage.getItem("payActive"));
                    if(payActive){
                        if(parseInt(payActive.status) === 1){
                            window.location.href= '../app/index.html';
                            
                        }
                    }
                    
                else{
                    window.location.href= '../app/index1.html';
                }

            }

And this is the function which makes the difference for each plan.

function openAddPopup() {
    //check first if user is PRO Copy
    const userStatus = localStorage.getItem("userKind");
    const user = userStatus;
    if (user) {
        app.router.load('contactEdit', { 'isFavorite': state.isFavorite });
    } else {
        alert("You can only add 3 elements on the free version");
    }
}

For the PRO plan I need to execute the full version of the app and for the FREE plan then the restricted version.

So, is it possible to append a JavaScript function to index.html and index1.html to, in case of the FREE plan, to do the second, but, in case of the PRO plan, the first?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖彼岸 2025-02-15 16:43:31

只要我今天早上醒来时就牢记一个简单的解决方案,并想与社区分享。

index.html中,我说:

userStatus = 'PRO';
localStorage.setItem( 'userKind', userStatus);

因此,在index1.html中:

const userStatus = localStorage.getItem("userKind");
    const user = userStatus;
    if (user) {
        localStorage.removeItem("userKind");
    }

然后在app.html

    //check first if user is PRO
    const userStatus = localStorage.getItem("userKind");
    const user = userStatus;

    if (user) {
        document.body.append("Pro version")
    } else {
        alert("Solo se pueden añadir 3 elementos en la versión Éstandar");
    }

中?当 auth api 将用户发送到应用程序时,如果它是Pro用户,则 api 将他/她重定向到index.html存储在localstorage userkind带有** pro **值的变量,但是如果它是标准用户,则API将其重定向她到index1.html userkind localstorage中的变量。这样可以确保如果用户的失去这种情况,他/她就可以访问标准版本。

这是一个工作示例:

index.html

运行<代码> index.html ,然后index1.html,因为您将充当auth API。

然后评论是否可以或必须改进。

As long as I woke up this morning with a simple solution in mind and want to share it with the community.

In the index.html I put this:

userStatus = 'PRO';
localStorage.setItem( 'userKind', userStatus);

So, in the index1.html this:

const userStatus = localStorage.getItem("userKind");
    const user = userStatus;
    if (user) {
        localStorage.removeItem("userKind");
    }

Then in the app.html this:

    //check first if user is PRO
    const userStatus = localStorage.getItem("userKind");
    const user = userStatus;

    if (user) {
        document.body.append("Pro version")
    } else {
        alert("Solo se pueden añadir 3 elementos en la versión Éstandar");
    }

How it works? When the Auth API send the user to the App, if it is a PRO user the API redirects him/her to the index.html which stores in localStorage the userKind variable with a **PRO** value, but if it is a Standard user, then the API redirects him/her to the index1.html which delete the userKind variable in localStorage. This way it is ensured that if user is PRO loses this condition, he/her just can access to the Standard version.

Here is a working example:

index.html

Run index.html and then index1.html, as you are going to function as the Auth API.

Then comment if it is ok or have to be improved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文