使用 Cloudflare Worker 免费搭建网址导航网站

开源项目

GitHub:https://github.com/sleepwood/CF-Worker-Dir/

CloudFlare Worker:https://workers.cloudflare.com/

搭建教程

  1. 首先,进入cloud flare - Worker

截图20200224180010.png

截图20200224180010.png

  1. 在 Cloudflare Worker 管理页面创建一个新的 Worker:

截图20200224180145.jpg

截图20200224180145.jpg

  1. 在Worker编辑页面左边代码:

截图20200224180437.jpg

截图20200224180437.jpg

/***  自定义网站配置 */
const config = {title: "自定义导航",                 //write your website titlesubtitle: "Cloudflare Workers Dir", //write your website subtitlelogo_icon: "sitemap",               //select your logo by semantic-ui icon (you can get more msg in:https://semantic-ui.com/elements/icon.html)hitokoto: true,                     //use hitokoto or notsearch:true,                        //enable search functionsearch_engine:[                     //choose search engine which you use{name:"百 度",template:"https://www.baidu.com/s?wd=$s"},{name:"谷 歌",template:"https://www.google.com/search?q=$s"},{name:"必 应",template:"https://www.bing.com/search?q=$s"},{name:"搜 狗",template:"https://www.sogou.com/web?query=$s"}],selling_ads: true,                  //Selling your domain or not.(turning on may be helpful for selling this domain by showing some ads.)sell_info:{domain:"example.com",price:500,                        //domain pricemon_unit:"yen sign",              //monetary unit contact:[                         //how to contact you{type:"envelope",               //contact type ("weixin","qq","telegram plane","envelope" or "phone")content:"info@example.com"}]                      },lists: [                            //Url list{name:"技术",icon:"code",list:[{url:"https://oschina.net/",name:"开源中国",desc:"程序员集散地"},{url:"https://v2ex.com",name:"V2EX",desc:"程序员集散地"},{url:"https://csdn.net/",name:"CSDN技术社区",desc:"程序员集散地"},{url:"https://github.com/",name:"Github",desc:"程序员集散地"},]},{name:"学习",icon:"graduation cap",list:[{url:"https://w3school.com.cn/",name:"W3school在线教程",desc:"程序员集散地"},{url:"https://runoob.com/",name:"菜鸟教程",desc:"程序员集散地"},{url:"https://segmentfault.com/",name:"思否社区",desc:"程序员集散地"},{url:"https://jianshu.com/",name:"简书",desc:"程序员集散地"},]}]
}
const el = (tag, attrs, content) => `<${tag} ${attrs.join(" ")}>${content}</${tag}>`;async function handleRequest(request) {const init = {headers: {'content-type': 'text/html;charset=UTF-8',},}return new Response(renderHTML(renderIndex(),config.selling_ads? renderSeller() :null), init);
}
addEventListener('fetch', event => {return event.respondWith(handleRequest(event.request))
})/*通过分析链接 实时获取favicon
* @url 需要分析的Url地址
*/
function getFavicon(url){if(url.match(/https{0,1}:\/\//)){//return "https://ui-avatars.com/api/?bold=true&size=36&background=0D8ABC&color=fff&rounded=true&name=" + url.split('//')[1];return "https://icon.occ.hk/get.php?url=" + url;}else{//return "https://ui-avatars.com/api/?bold=true&size=36&background=0D8ABC&color=fff&rounded=true&name=" + url;return "https://icon.occ.hk/get.php?url=http://" + url;} 
}/** Render Functions*  渲染模块函数*/function renderIndex(){const footer = el('footer',[],el('div',['class="footer"'],'Powered by' + el('a',['class="ui label"','href="https://github.com/sleepwood/cf-worker-dir"','target="_blank"'],el('i',['class="github icon"'],"") + 'Cf-Worker-Dir') + ' © Base on ' + el('a',['class="ui label"'],el('i',['class="balance scale icon"'],"") + 'MIT License')));return renderHeader() + renderMain() + footer;
}function renderHeader(){const item = (template,name) => el('a',['class="item"',`data-url="${template}"`],name);var nav = el('div',['class="ui large secondary inverted menu"'],el('div',['class="item"'],el('p',['id="hitokoto"'],'条条大路通罗马')))var title = el('h1',['class="ui inverted header"'],el('i',[`class="${config.logo_icon} icon"`],"") + el('div',['class="content"'],config.title + el('div',['class="sub header"'],config.subtitle)));var menu = el('div',['id="sengine"','class="ui bottom attached tabular inverted secondary menu"'],el('div',['class="header item"'],' ') + config.search_engine.map((link,key) =>{if(key == 0){return el('a',['class="active item"',`data-url="${link.template}"`],link.name);}else{return item(link.template,link.name);}}).join(""))var input = el('div',['class="ui left corner labeled right icon fluid large input"'],el('div',['class="ui left corner label"'],el('img',['id="search-fav"','class="left floated avatar ui image"','src="https://www.baidu.com/favicon.ico"'],"")) + el('input',['id="searchinput"','type="search"','placeholder="搜索你想要知道的……"','autocomplete="off"'],"") + el('i',['class="inverted circular search link icon"'],""));return el('header',[],el('div',['id="head"','class="ui inverted vertical masthead center aligned segment"'],(config.hitokoto ? el('div',['id="nav"','class="ui container"'],nav) : "") + el('div',['id="title"','class="ui text container"'],title + (config.search ? input + menu :"") + `${config.selling_ads ? '<div><a id="menubtn" class="red ui icon inverted button"><i class="heart icon"></i> 喜欢此域名 </a></div>' : ''}`)))
}function renderMain() {var main = config.lists.map((item) => {const card = (url,name,desc)=> el('a',['class="card"',`href=${url}`,'target="_blank"'],el('div',['class="content"'],el('img',['class="left floated avatar ui image"',`src=${getFavicon(url)}`],"") + el('div',['class="header"'],name) + el('div',['class="meta"'],desc)));const divider = el('h4',['class="ui horizontal divider header"'],el('i',[`class="${item.icon} icon"`],"")+item.name);var content = el('div',['class="ui four stackable cards"'],item.list.map((link) =>{return card(link.url,link.name,link.desc);}).join(""));return el('div',['class="ui basic segment"'],divider + content);}).join("");return el('main',[],el('div',['class="ui container"'],main));
}function renderSeller() {const item = (type,content) => el('div',['class="item"'],el('i',[`class="${type} icon"`],"") + el('div',['class="content"'],content));var title = el('h1',['class="ui yellow dividing header"'],el('i',['class="gem outline icon"'],"") + el('div',['class="content"'],config.sell_info.domain + ' 正在出售'));var action = el('div',['class="actions"'],el('div',['class="ui basic cancel inverted button"'],el('i',['class="reply icon"'],"") + '返回'));var contact = config.sell_info.contact.map((list) => {return item(list.type,list.content);}).join("");var column = el('div',['class="column"'],el('h3',['class="ui center aligned icon inverted header"'],el('i',['class="circular envelope open outline grey inverted icon"'],"") + '联系我') + el('div',['class="ui relaxed celled large list"'],contact));var price = el('div',['class="column"'],el('div',['class="ui large yellow statistic"'],el('div',['class="value"'],el('i',[`class="${config.sell_info.mon_unit} icon"`],"") + config.sell_info.price)));var content = el('div',['class="content"'],el('div',['class="ui basic segment"'],el('div',['class="ui two column stackable center aligned grid"'],el('div',['class="ui inverted vertical divider"'],'感兴趣?') + el('div',['class="middle aligned row"'],price + column))));return el('div',['id="seller"','class="ui basic modal"'],title + content + action);
}function renderHTML(index,seller) {return `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>${config.title} - ${config.subtitle}</title><link href="https://cdn.jsdelivr.net/npm/semantic-ui-css@2.4.1/semantic.min.css" rel="stylesheet"><link href="https://cdn.jsdelivr.net/gh/sleepwood/cf-worker-dir@0.1.1/style.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/semantic-ui-css@2.4.1/semantic.min.js"></script></head><body>${index}${config.selling_ads ? seller : ''}<script src="https://v1.hitokoto.cn/?encode=js&select=%23hitokoto" defer></script><script>$('#sengine a').on('click', function (e) {$('#sengine a.active').toggleClass('active');$(e.target).toggleClass('active');$('#search-fav').attr('src',$(e.target).data('url').match(`+/https{0,1}:\/\/\S+\//+`)[0] + '/favicon.ico') ;});$('.search').on('click', function (e) {var url = $('#sengine a.active').data('url');url = url.replace(`+/\$s/+`,$('#searchinput').val());window.open(url);});/* 鼠标聚焦时,回车事件 */$("#searchinput").bind("keypress", function(){if (event.keyCode == 13){// 触发需要调用的方法$(".search").click();}});$('#menubtn').on('click', function (e) {$('#seller').modal('show');});</script></body></html>`
}

原地址:https://github.com/sleepwood/CF-Worker-Dir/edit/master/index.js

  1. 根据自身需要修改代码内容
  2. Ctrl+s发布 或者 点击Save and deploy

截图20200224180712.jpg

截图20200224180712.jpg

转载申明

转载请注明出处:365文档网

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/177006.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

三菱PLC小项目系列—传送带多地控制

目录 一、项目描述 二、IO口分配 三、项目程序 四、总结 一、项目描述 化工厂中有传送带进行原料传送加工&#xff0c;当按下启动按钮SB1或者SB2&#xff0c;电机M1接通控制传送带运转&#xff0c;直至按下停止按钮SB3&#xff0c;电机停止并使传送带停止运行。 二、IO口分…

Linux技能篇-软链接和硬链接

文章目录 前言一、硬链接是什么&#xff1f;二、软链接是什么&#xff1f;三、硬链接和软链接的区别和共性1.区别2.共同点 总结 前言 在Linux系统中&#xff0c;有两个容易混淆的概念&#xff0c;就是软链接&#xff08;Soft Link&#xff09;和硬链接&#xff08;Hard Link&a…

连小白都在用的电子期刊制作网站

你是不是也想制作一份精美的电子期刊&#xff0c;却苦于没有专业的技能和工具&#xff1f;现在&#xff0c;有一款制作电子期刊的网站&#xff0c;连小白都能轻松制作电子期刊&#xff01;它就是今天要介绍的——【FLBOOK在线制作电子杂志平台】&#xff01; 【FLBOOK在线制作电…

国际阿里云:无法访问ECS实例中的服务的排查方法!!!

操作场景 无法访问ECS实例中的服务可能有以下原因&#xff1a; 可能原因 排查方案 ECS实例的安全组未开放相应端口 检查ECS实例安全组规则 ECS实例中&#xff0c;该服务未启动/开启或服务对应端口未被监听 检查服务状态及端口监听状态 ECS实例内防火墙设置错误 检查ECS…

Git之分支与版本->课程目标及知识点的应用场景,分支的场景应用,标签的场景应用

1.课程目标及知识点的应用场景 Git分支和标签的命名规范 分支 dev/test/pre/pro(即master) dev:开发环境--windows (自己的电脑) test:测试环境--windows/linux (公司专门的测试电脑 pre:灰度环境(非常大的公司非常重要的项目) pro:正式环境 灰度环境与正式环境的服务器配置…

实用篇-ES-RestClient操作文档

一、RestClient案例准备 对es概念不熟悉的话&#xff0c;先去看上面的 实用篇-ES-索引库和文档&#xff0c;不建议基础不牢就直接往下学 ES官方提供了各种不同语言的客户端&#xff0c;用来操作ES。这些客户端的本质就是组装DSL语句&#xff0c;通过http请求来发送给ES。 官…

怎样正确选择等保测评机构开展等保测评工作?

随着大家对网络安全的重视&#xff0c;越来越多的企业需要做等保测评了。很多小伙伴想知道怎样正确选择等保测评机构开展等保测评工作&#xff1f;这里就给大家简单说说。 怎样正确选择等保测评机构开展等保测评工作&#xff1f; 【回答】&#xff1a;正确选择等保测评机构开展…

Tomcat学习

一、入门 在webapp里面必须先创建一个文件夹&#xff0c;文件夹里面放的内容&#xff0c;才会被访问到。 创建一个javaweb项目后 二、servlet 1.概述 2.servlet生命周期 3.servlet实例的创建时机 4.Servlet实例的初始化参数 5.HTTP状态码 6.servelet返回JSON数据 7.服务端设置…

源码级JVS低代码功能新增:动态配置、逻辑多级循环嵌套等等

低代码更新功能 新增: 1.下拉组件选项新增动态配置&#xff1b; 选项的内容可以根据特定的条件或数据源进行动态变化的功能&#xff0c;通过动态配置&#xff0c;用户可以灵活地设置下拉组件的选项内容&#xff0c;例如从数据库或其他数据源中获取选项数据&#xff0c;或者根…

C++之Max

背景 想学习数据结构&#xff0c;这是看的课程的习题&#xff0c;讲课老师用的是类C语言&#xff0c;具体的实现还是得自己来。 准备工作 用开发工具Microsoft Visual Studio(VS)建立一个空白的C控制台项目 选择项目的存储路径 成功建立 我在 Microsoft Visual Studio中用…

OSG路径动画:osg::AnimationPath示例

一、效果 飞船绕地球飞行 二、源码 // osg_AnimationPath.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include <windows.h> #include <iostream> #include <osgViewer/Viewer>