Home Backend Development PHP Tutorial js implementation to obtain website search source code

js implementation to obtain website search source code

Mar 29, 2018 am 09:35 AM
javascript source code Site search

This article mainly shares with you the js implementation of obtaining website search source code. Introducing the following code into all pages can realize the function of collecting system sources. Global unified source information can be used in any page. I hope it can help. Everyone.

var args = {
    mySite:"localhost",
    subSite:"子网站,比如移动端: m.xxx.com"
}
var index = (function(a) {
    var c = "";
    var d = args.mySite;
    a(function() {
        var g = function() {
            return function(k, l, j) {
                var h = j * 24 * 60 * 60 * 1000;
                var i = new Date();
                i.setTime(i.getTime() + h);
                var e = "; expires=" + i.toGMTString();
                document.cookie = k + "=" + escape(l) + e + "; path=/"
            }
        };
        try {
            if (document.referrer.indexOf(d) <= 0 || document.referrer.indexOf(d) > 10) {
                g().call(window, "regCompanyName", document.referrer.substring(0, 40) + "||" + window.location.href, 30)
            }
        } catch (f) {

        }
    });
    var b = function() {
        try {
            if (getCookie) {
                return getCookie
            }
        } catch (f) {}
        return function(e) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(e + "=");
                if (c_start != -1) {
                    c_start = c_start + e.length + 1;
                    c_end = document.cookie.indexOf(";", c_start);
                    if (c_end == -1) {
                        c_end = document.cookie.length
                    }
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return null
        }
    };
})(jQuery);

//媒体
var media = "";
//媒体细分
var mediaSubpide = "";
//注册渠道。(直接赋值)
var registerChannel = "";
//终端,根据用户使用设备判断
var terminal = "";
//数据来源,根据cookie确定
var dataSource = "";
//当前链接
var localUrl = window.location.href;

var userChannel = {
    //媒体
    Media: function(channelInfo){
        channelInfo=channelInfo.toLowerCase();
        if(channelInfo.indexOf("||") == 0 && (channelInfo.indexOf(args.mySite) >= 0)){
            //媒体  无法判断(如直接搜索) 
            media = "网址打开或站内跳转";  //媒体
            mediaSubpide =  "";       //媒体细分

            // 无法获取referrer的来源的情况有:
            //1、个别平台外链使用noreferrer;
            //2、https跳转http;
            //3、网页重定向...
            //可在外链中植入可判定的参数如www.xxx.com&tag=zhihu
            if(channelInfo.indexOf("zhihu")>=0){
                media = "知乎";
                mediaSubpide = "";
            }
        }else if(channelInfo.indexOf("baidu.com") != -1){
            media = "百度";                       //媒体
            if(channelInfo.indexOf(&#39;utm_medium=cpc&#39;) != -1){
                mediaSubpide = "sem";         //媒体细分
            }else if(channelInfo.indexOf(&#39;utm_medium=cpc&#39;) == -1){
                mediaSubpide = "seo";         //媒体细分
            }else{
                mediaSubpide = "其它";      //媒体细分
            }
        }else if(channelInfo.indexOf(&#39;haosou.com&#39;) != -1 || channelInfo.indexOf(&#39;so.com&#39;) != -1){
            media = "好搜";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf(&#39;sogou.com&#39;) != -1){
            media = "搜狗";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf(&#39;sm.cn&#39;) != -1){
            media = "神马";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf(&#39;bing.com&#39;) != -1){
            media = "必应";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf(&#39;google.com&#39;) != -1){
            media = "google";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf(&#39;douban.com&#39;) != -1){
            media = "豆瓣";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }else if(channelInfo.indexOf("zhihu.com") != -1){
            media = "知乎";
            mediaSubpide = "无法判断";        
        }   
        else if(channelInfo.indexOf("toutiao") != -1){
            media = "今日头条";
            mediaSubpide = "无法判断";        
        }
        else{
            media = "其它";                       //媒体
            mediaSubpide = "无法判断";        //媒体细分
        }
    
        var mediaInfo=new Array(media,mediaSubpide);
        return mediaInfo;
    },
    //终端
    Terminal: function(){
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))){
            terminal = "移动端";
            return terminal;
        }else{
            terminal = "PC端";
            return terminal;
        }
    },
    
    //注册渠道。通过判断当前页面url获取
    RegisterChannel: function(){
        if(localUrl.indexOf(args.mySite)!= -1 ){
            registerChannel = args.mySite+"网站注册";
            return registerChannel;
        }else if(localUrl.indexOf(args.subSite)!= -1){
            registerChannel = args.subSite+"网站注册";
            return registerChannel;
        }else{
            registerChannel = "未知";
            return registerChannel;
        }
    }
};

//通用设置cookie方法
function setCookie(name, value, days) {
    var cookieTime = days * 24 * 60 * 60 * 1000;
    var d = new Date();
    d.setTime(d.getTime() + cookieTime);
    var cookieExpires = "; expires=" + d.toGMTString();
    document.cookie = name + "=" + escape(value) + cookieExpires + "; path=/";
}
//通用读取cookie方法
function getCookie(name) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0] == name)
            return unescape(arr[1]);
    }
    return "";
}

//排除站内跳转的情况,以免window.name被错误覆盖
if(document.referrer.indexOf(args.mySite)<=0){
    window.name=document.referrer.substring(0,40)+"||"+window.location.href;
}

//使用案例
dataSource = getCookie(&#39;regCompanyName&#39;);
if(!dataSource || ""== dataSource || typeof(dataSource)== "undefined") {
    //当cookie无法使用时,优先使用window.name
    dataSource = (window.name) ? window.name : "";
}

var judgeMedia = userChannel.Media(dataSource);
var judgeTerminal = userChannel.Terminal();
var judgeRegisterChannel = userChannel.RegisterChannel();

console.log(judgeMedia+&#39; &#39;,judgeTerminal+&#39; &#39;,judgeRegisterChannel+&#39; &#39;);
Copy after login

The above is the detailed content of js implementation to obtain website search source code. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

How to use insertBefore in javascript How to use insertBefore in javascript Nov 24, 2023 am 11:56 AM

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

See all articles