简体   繁体   中英

how to Replace a text with an element in site - Cloudflare app

The task of this app is to identify a URL ( refferer link) and to replace the telephone number or an image inside the site with another phone number or image. For example, if a person enters our site from site A, replace the phone number that is on our site to X, and if one enters our site from site B, replace the phone number on our site to Y. My code is as follows but it doesn't work. Please guide me.

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;
 }

}
}())

If it's only for your own site, a Cloudflare app isn't the answer. Use a Cloudflare worker on your site instead.

The Cloudflare worker could save the referrer in a cookie the first time the user goes to your site, and then show the appropriate phone number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM