게시판 » Greasy Fork 피드백

\xa0 replaced with space when publish a script

§
작성: 2022-11-09

There are several \xa0 in match function parameter, and they are replaced with space char after publish, for example:

script: https://greasyfork.org/zh-CN/scripts/435569/code line 1139:

author = meta.match(/作者:\s*(.*?) /); replaced with author = meta.match(/作者:\s*(.*?) /);

JasonBarnabe관리자
§
작성: 2022-11-10

If I inspect that line with the browser console, it's a nbsp:

document.querySelectorAll(".linenums li")[1138].innerHTML 
"<span class=\"pln\">                author </span><span class=\"pun\">=</span><span class=\"pln\"> meta</span><span class=\"pun\">.</span><span class=\"pln\">match</span><span class=\"pun\">(</span><span class=\"str\">/作者:\\s*(.*?)&nbsp;/</span><span class=\"pun\">);</span>" 

What makes you think it's not working? Are you entering a literal non-breaking space or are you entering the escape code (\xa0)?

§
작성: 2022-11-10

It's a non-breaking space char in the code, I copied it from the webpage html code, when I copy the code from tampermonkey editor to the gf code textarea and submit, it becomes a   space.

JasonBarnabe관리자
§
작성: 2022-11-10

So are you writing \xa0 in your code and expecting it to remain \xa0 but it's becoming an actual non-breaking space?

§
작성: 2022-11-10
수정: 2022-11-10

Yes, I write a \xa0 char, not literal \xa0, but it becomes a &nbsp; char.

JasonBarnabe관리자
§
작성: 2022-11-11

Tried an escape-code \xa0 in this test script (lines 11 and 12) - it stayed in the escapeed form that I wrote it in.

Can you upload your full code somewhere else and then provide a link? Then I'll test further.

§
작성: 2022-11-11

I upload it here, https://files.catbox.moe/p46aqm.js

There are 4 occurrences:

line 551

meta = meta.replace(/\n\s+/g, "\n").replace(/:\n+/g, ": ").replace(" ", " ").replace(/(作者|出版社|出品方|副标题|原作名|译者|出版年|页数|定价|装帧|丛书|ISBN): */g, "【$1】").replace(/\n([^【])/g, "$1").replace(/【热度】\n/, "");

line 566

meta =【书名】${bookname}\n+ jQuery(ele).parent().parent().find("dd").text().replace(/\n\s+/g, "\n").replace(/(\n(馆藏纸本|包库全文|部分阅读|试读|汇雅电子书))+\n/g, "\n").replace(/\s*(总被引:|被图书引:)/g, ",$1").replace("收藏馆:", "【热度】收藏馆:").replaceAll(" ", "").replace(/(作者|出版社|出版日期|页数|丛书名|简介|ISBN|主题词|分类) : /g, "\n【$1】").trim() +\n【链接】${pageurl.split("/search")[0] + "/" + ele_title.attr("href").split("&fenlei")[0]};

line 1139

author = meta.match(/作者:\s*(.*?) /);

line 1141

press = meta.match(/出版社:\s*(.*?) /);

JasonBarnabe관리자
§
작성: 2022-11-18

I don't see any \x escape codes at all in https://files.catbox.moe/p46aqm.js. I do see the non-breaking spaces. When I copy paste it and post it to the site, it's still the same character.

So it looks exactly the same as the file you provided.

§
작성: 2022-11-18

I download https://files.catbox.moe/p46aqm.js and search \xa0 in sublime text and find occurences in line 551/ 566 /1139 / 1141.

댓글 남기기

댓글을 남기려면 로그인하세요.