如何用站点中的元素替换文本-Cloudflare应用

问题描述 投票:0回答:1

此应用程序的任务是识别URL(中继链接),并将网站内的电话号码或图片替换为另一个电话号码或图片。例如,如果某人从站点A进入我们的站点,请将我们站点上的电话号码替换为X,并且如果某人从站点B进入我们的站点,则将我们站点上的电话号码替换为Y。我的代码如下,但不起作用。请指导我。

install.json

{
"resources": {
    "body": [{
        "type": "script",
        "src": "./app.js"
    }]
},
    "options": {
        "properties": {
            "referrer": {
                "order": 1,
                "type": "string",
                "title": "The refferer url : "
            },
            "text": {
                "order" : 2,
                "type": "string",
                "title": "Enter the phone number you want to replace",
                "products": ["plus", "pro"]
            },
            "location": {
                "title": "Location",
                "description": "Select the part of your page which contains a Text ( for example : phone number) you’d like to change",
                "type": "object",
                "format": "element",
                "default": {
                    "selector": "body",
                    "method": "prepend"
                  },
                "order": 1
            },
            "slides": {
                "title": "Slides",
                "type": "array",
                "maxItems": 10,
                "order": 2,
                "items": {
                  "type": "object",
                  "title": "Slide",
                  "properties": {
                    "image": {
                      "title": "Image",
                      "type": "string",
                      "order": 1,
                      "format": "image"
                    },
                    "description": {
                      "title": "Description",
                      "description": "This text is used as the image’s title and alt text, important for SEO.",
                      "default": "A wonderful image portraying a better future.",
                      "order": 2,
                      "type": "string",
                      "maxLength": 200
                    }
            }
        }
    }
        }       
    }

app.js

(function () {
'use strict'

var options = INSTALL_OPTIONS
var element

if (document.referrer.trim() == option.refferer.trim()) {

function updateElements () {
 element = INSTALL.createElement(options.location, element);
    if (!element) return
    element.textContent = options.text;
 }

}
}())
javascript cloudflare cloudflare-apps
1个回答
0
投票

[如果仅用于您自己的网站,则Cloudflare应用不是答案。改为在您的网站上使用Cloudflare工作者。

Cloudflare工作者可以在用户第一次访问您的站点时将引荐来源网址保存在cookie中,然后显示适当的电话号码

© www.soinside.com 2019 - 2024. All rights reserved.