当前位置: 首页 > wzjs >正文

大连百度网站快速优化网络服务部工作计划

大连百度网站快速优化,网络服务部工作计划,v2ex wordpress,怎么自己设计logo图标一、目标: 实现传入参数--platformmac,将浏览器获取到的操作系统变为macOS并且可以通过creepjs和browserscan的检测。 二、js如何判断操作系统是否为Mac 方法比较多,这里我们只能挨个列出来,然后挨个修改 1 . 通过navigator.pla…

一、目标:

  • 实现传入参数--platform=mac,将浏览器获取到的操作系统变为macOS
  • 并且可以通过creepjs和browserscan的检测。

二、js如何判断操作系统是否为Mac

方法比较多,这里我们只能挨个列出来,然后挨个修改

  • 1 . 通过navigator.platform
console.log(navigator.platform)

输出:

MacIntel
  • 2 . 通过navigator.userAgent

正常mac的UA类似长这样:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

function detectOS() {const userAgent = navigator.userAgent.toLowerCase();if (userAgent.includes('win')) {return 'Windows';} else if (userAgent.includes('mac')) {return 'Mac';}return '其他系统';   
}console.log(detectOS())

输出:

Mac
  • 3 . 通过navigator.userAgentData
let tmp = await navigator.userAgentData.getHighEntropyValues(["platform", "platformVersion"])
console.log("操作系统:", tmp.platform)
console.log("版本号:", tmp.platformVersion)

输出:

操作系统: macOS
版本号: 10.11.2
  • 4 . 通过字体
function detectOSByFont() {// 定义系统特征字体(按检测优先级排序)const osFonts = {mac: ["Geneva", "Helvetica Neue", "Luminari"],win: ["Segoe UI", "Ink Free", "Segoe UI Emoji"]};// 字体检测方法const isFontAvailable = fontName => {try {await (new FontFace("Helvetica Neue", `local("${fontName} Neue"`)).load()return true;} catch (e) {return false;}};// 优先检测Mac字体for (const font of osFonts.mac) {if (isFontAvailable(font)) return "Mac";}// 其次检测Windows字体for (const font of osFonts.win) {if (isFontAvailable(font)) return "Windows";}// 最终回退到UserAgent检测const ua = navigator.userAgent;if (/Mac/i.test(ua)) return "操作系统:Mac";if (/Win/i.test(ua)) return "操作系统:Windows";return "其他操作系统";   
}console.log(detectOSByFont())

输出:

Mac
  • 5.通过特性
if('BarcodeDetector' in window){console.log('是Mac')
}else{console.log('不是Mac')
}

输出:

是Mac

三、修改navigator.platform

  • 打开文件 \third_party\blink\renderer\core\execution_context\navigator_base.cc

  • 找到函数:

String GetReducedNavigatorPlatform() {
  • 追加几行:
String GetReducedNavigatorPlatform() {// 开始追加 =====================================base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess();std::string platform = base_command_line->GetSwitchValueASCII("platform"); if (platform == "mac"){return "MacIntel";}// 结束追加 ==================================

四、修改navigator.userAgent

  • 打开文件:\components\embedder_support\user_agent_utils.cc

  • 找到:

std::string GetUserAgent(UserAgentReductionEnterprisePolicyState user_agent_reduction) {std::optional<std::string> custom_ua = GetUserAgentFromCommandLine();if (custom_ua.has_value()) {return custom_ua.value();}return GetUserAgentInternal(user_agent_reduction);
}
  • 替换为:
std::string GetUserAgent(ForceMajorVersionToMinorPosition force_major_to_minor,UserAgentReductionEnterprisePolicyState user_agent_reduction) {absl::optional<std::string> custom_ua = GetUserAgentFromCommandLine();if (custom_ua.has_value()) {return custom_ua.value();}// 开始修改========================//return GetUserAgentInternal(user_agent_reduction); // 133版base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess();std::string ignores = base_command_line->GetSwitchValueASCII("ignores"); if(!base_command_line->HasSwitch("user-agent") && ignores.find("useragent") == std::string::npos){std::string ua;std::string target;std::string replacemen; std::string result = ua;size_t pos;std::string platform = base_command_line->GetSwitchValueASCII("platform");if (platform == "mac"){target = "Windows NT 10.0; Win64; x64";replacement = "Macintosh; Intel Mac OS X 10_11_2"; pos = 0;while ((pos = result.find(target, pos))!= std::string::npos) {result.replace(pos, target.length(), replacement);pos += replacement.length();}}return result;   }else{return GetUserAgentInternal(user_agent_reduction); }// 结束修改=======================================
}

注意:不同大版本的源代码会略有不同,不要直接覆盖,注意理解。

五、修改navigator.userAgentData

  • 还是打开:\components\embedder_support\user_agent_utils.cc

  • 找到函数:

std::string GetPlatformForUAMetadata() {
  • 追加几行:

std::string GetPlatformForUAMetadata() {// 开始追加 =================================base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess();std::string platform = base_command_line->GetSwitchValueASCII("platform");if (platform == "mac"){return "macOS";}else if (platform == "win"){return "Windows";}else if (platform == "linux"){return "Linux";}// 结束追加===========================================

六、修改font

  • 打开:\third_party\blink\renderer\core\css\css_font_family_value.cc

  • 找到函数:

CSSFontFamilyValue* CSSFontFamilyValue::Create(
  • 追加几行:
CSSFontFamilyValue* CSSFontFamilyValue::Create(const AtomicString& family_name) {// 开始追加=======================================base::CommandLine* base_command_line = base::CommandLine::ForCurrentProcess();std::string ignores = base_command_line->GetSwitchValueASCII("ignores"); std::string now_font_str = family_name.GetString().Utf8();if (base_command_line->HasSwitch("finger-log")) {std::cerr << "调用canvas字体: " << now_font_str << std::endl;}if(ignores.find("fonts") == std::string::npos){int seed;auto now = std::chrono::system_clock::now();std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);int int_now = static_cast<int>(now_time_t);if (base_command_line->HasSwitch("fingerprints")) {std::istringstream(base_command_line->GetSwitchValueASCII("fingerprints")) >> seed; }else{seed = int_now;}std::vector<std::string> stringsAarry = {"Goudy Old Style", "Bell MT", "Browallia New", "Rod", "Zurich Ex BT", "BinnerD", "Gill Sans Ultra Bold Condensed", "INTERSTATE", "Arabic Typesetting", "Fransiscan", "AvantGarde Md BT", "Segoe Fluent Icons", "Broadway", "Bodoni MT Poster Compressed", "Miriam Fixed", "PetitaBold", "DFKai-SB", "Poster", "MS Outlook", "DIN", "Charlesworth", "Cuckoo", "VisualUI", "Geometr231 Lt BT", "Denmark", "Adobe Garamond", "Eras Bold ITC", "Meiryo", "MS PMincho", "Herald", "Didot", "Bodoni MT", "Bazooka", "Kristen ITC", "MS Mincho", "Khmer UI", "Lydian BT", "ShelleyVolante BT", "Kailasa", "Pickwick", "GOTHAM", "ZapfEllipt BT", "Geometr231 BT", "MT Extra", "Papyrus", "Mrs Eaves", "Letter Gothic", "Albertus Extra Bold", "Vladimir Script", "Chalkboard SE", "SCRIPTINA", "Storybook", "OzHandicraft BT", "Wingdings 2", "Tunga", "PosterBodoni BT", "Baskerville Old Face"};auto selectedArray = selectRandomFonts2(stringsAarry, 199, seed);if (std::find(selectedArray.begin(), selectedArray.end(), now_font_str) != selectedArray.end()) { //如果在selectedArray中return MakeGarbageCollected<CSSFontFamilyValue>(AtomicString("sans-serif"));}std::vector<std::string> winFontsAarry = {"Segoe Fluent Icons", "Ink Free", "Bahnschrift", "Segoe MDL2 Assets", "HoloLens MDL2 Assets", "Segoe UI Emoji", "Javanese Text", "Leelawadee UI", "Nirmala UI", "Myanmar Text", "Gadugi", "Aldhabi", "Lucida Console", "Cambria Math"};if (base_command_line->GetSwitchValueASCII("platform") == "mac"){std::vector<std::string> macFontsAarry = {"Helvetica Neue", "Geneva", "Kohinoor Devanagari Medium", "Luminari", "PingFang HK Light", "InaiMathi Bold", "PGalvji", "Chakra Petch" };if(std::find(winFontsAarry.begin(), winFontsAarry.end(), now_font_str) != winFontsAarry.end()){//std::cerr << "now_font_str:"<< now_font_str << std::endl;return MakeGarbageCollected<CSSFontFamilyValue>(AtomicString("sans-serif"));}else if(std::find(macFontsAarry.begin(), macFontsAarry.end(), now_font_str) != macFontsAarry.end()){return MakeGarbageCollected<CSSFontFamilyValue>(AtomicString("Arial"));}} }// 结束追加=======================================  
  • 我还定义了一个函数:
std::vector<std::string> selectRandomFonts2(const std::vector<std::string>& fontArray, size_t count, unsigned int seed) {// 随机选多个std::mt19937 rng(seed);std::uniform_int_distribution<size_t> dist(0, fontArray.size() - 1);std::vector<std::string> selectedFonts;selectedFonts.reserve(count);std::vector<bool> selected(fontArray.size(), false);while (selectedFonts.size() < count) {size_t index = dist(rng);if (!selected[index]) {selectedFonts.push_back(fontArray[index]);selected[index] = true;}}return selectedFonts;
}

这里写的很乱。但只需要理解原理即可,就是将mac的字体列表, {"Helvetica Neue", "Geneva", "Kohinoor Devanagari Medium", "Luminari", "PingFang HK Light", "InaiMathi Bold", "PGalvji", "Chakra Petch" } 全部能有有效返回。

七、追加window.BarcodeDetector

  • 打开 \third_party\blink\renderer\platform\runtime_enabled_features.json5

  • 找到:

   {name: "BarcodeDetector",status: {// Built-in barcode detection APIs are only available from some// platforms. See //services/shape_detection."Android": "stable","ChromeOS_Ash": "stable","ChromeOS_Lacros": "stable","Mac": "stable","default": "test",},base_feature: "none",}
  • 替换成:
   {name: "BarcodeDetector",status: {// Built-in barcode detection APIs are only available from some// platforms. See //services/shape_detection."Android": "stable","ChromeOS_Ash": "stable","ChromeOS_Lacros": "stable","Mac": "stable",// 追加一行 ============================"Win": "stable","default": "test",},base_feature: "none",}

八、编译:

ninja -C out/Default chrome

九、测试效果:

  • 测试站点1:https://www.browserscan.net/zh/
  • 测试站点2:https://abrahamjuliot.github.io/creepjs/
./chrome.exe --paltform=mac

在这里插入图片描述


文章转载自:

http://tNa11xYo.tnzwm.cn
http://wSRDC2vO.tnzwm.cn
http://wXZBJHt2.tnzwm.cn
http://gAJfYSJ0.tnzwm.cn
http://u4yRszSp.tnzwm.cn
http://WejIZY1d.tnzwm.cn
http://dyeGLN5q.tnzwm.cn
http://8rmJsXsW.tnzwm.cn
http://KlkGCH3I.tnzwm.cn
http://op8mHE0F.tnzwm.cn
http://JHzfey20.tnzwm.cn
http://86ekWssG.tnzwm.cn
http://cDvUC0m0.tnzwm.cn
http://O21NSzAb.tnzwm.cn
http://fxW4BjII.tnzwm.cn
http://XrpMLwen.tnzwm.cn
http://VBHqpNRp.tnzwm.cn
http://GCmGTkkt.tnzwm.cn
http://mC3275DJ.tnzwm.cn
http://vmMDA5cu.tnzwm.cn
http://qNB83oVL.tnzwm.cn
http://Gk6Bm9pq.tnzwm.cn
http://8ivoznXG.tnzwm.cn
http://h6yvmARr.tnzwm.cn
http://q1UjYMmd.tnzwm.cn
http://fKBkTBM8.tnzwm.cn
http://WO2WyD3V.tnzwm.cn
http://19PCuDho.tnzwm.cn
http://5QPpOGlb.tnzwm.cn
http://QnnOW2tS.tnzwm.cn
http://www.dtcms.com/wzjs/690243.html

相关文章:

  • 软件做网站 编程自己写网站建设的业务规划
  • js素材网站做代刷网站赚钱不
  • 莱芜手机网站设计公司最近几年做电影网站怎么样
  • wp如何做网站地图现在最流行的网站开发工具
  • 网站页脚需要放什么谷歌外贸网站
  • 传媒网站制作做网站去哪找客户
  • 长春网站建设方案推广家庭室内装修设计公司
  • 哪个网站财经做的最好电子商务网站中最基本的系统是
  • 客户端 网站开发 手机软件开发哪个软件是网页编辑软件
  • 一元云淘网站开发手机视频网站开发
  • 有没有专门发布毕业设计代做网站网站建设顾问站建
  • 神木自适应网站开发wordpress 开发商城
  • wordpress 建站插件个人简历样本
  • 企业怎么建网站网站商城建设费用
  • 网站建设及维护成本铁岭做网站哪家好
  • wordpress站点图标正能量不良网站推荐2020
  • 网站数据库怎么配置石家庄网站建设浩森宇特
  • 杭州网站建设手机版外包做网站
  • 九江市住房和城乡建设局官方网站织梦软件展示网站源码
  • 青岛网站推广服务租号网站开发
  • 网站建设方案交换认苏州久远网络网站动态页面怎么做
  • 建设银行海淀支行 网站商城站人工售票时间表
  • 网站建设所需人员uc浏览器在线网页
  • 烟台网站建设 制作 推广装饰行业网站建设方案
  • 网站排名优化学习广州公司注册最新流程
  • 网站建设要学习什么建设企业网站得花多少
  • 电信 网站备案iis下建多个网站
  • 婚纱摄影平台新网网站内部优化
  • 有公网ip 如何做一网站SSC网站开发H5
  • 免费做字体的网站上海做网站站优云一一十七