-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mass delete specific tags which appear for every line with epubeditor #4
Comments
There’s actually a way to remove all those tags in Calibre or VSC using Regex. http://stackoverflow.com/questions/43577528/ddg#43578165 its really simple and once you get the hang of it, it takes seconds to clean up epubs. |
ahhh I'm really not that much of a technical person so I don't know what regex is? I see that mode in Calibre but I dunno how to use it haha, I always preferred using the scripts in epubeditor because it's instantaneous effect with rooting out all possible cases fast 😅 but thank you very much for your help! |
You just enter it in the “find & replace” bar and it finds the code you want to remove. Keep the replace box empty and it will remove what you want for the entire epub. The link above is very beginner friendly and already gives you the code. You just have to replace h1 with the codes displayed above. Or you can shorten/change them. |
This is the script you need let toChange = [...dom.querySelectorAll("h2, p, span")];
for(let s of toChange) {
s.removeAttribute("style");
}
return 0 < toChange.length; How to understand this "h2, p, span" is a CSS selector that says: all <h2> <o> & <style> tags. let toChange = [...dom.querySelectorAll("h2, p, span")]; Says: create a list of all <h2>, <p> & <style> tags and call that list "toChange" for(let s of toChange) {
} Says: take each item in the list called "toChange", and do something with it. s.removeAttribute("style"); This says remove the style attribute from the something called "s" So for(let s of toChange) {
s.removeAttribute("style");
} Says, remove the style attribute from every tag in the list "toChange" return 0 < toChange.length; This is boilerplate. What it's doing is telling EpubEditor if any tag was changed. EpubEditor needs to know if anything was changed, so it can write the changes. For my notes: 32 minutes work. |
|
Please provide an example |
AH i'm sorry! it was my error with a misplaced variable in the script that i had written incorrectly. but it works properly now for the div tag too! thank you again for your help and explanation!! :D |
You are welcome.
|
ahhhh im sorry for the bother again, but i actually made another error that wrecked my epub instead. it had actually worked before, but now i cant rewrite the script to do the same thing, about deleting both the tags and the text within the tags as well. probably because there are so many other unnecessary tags i deleted that it affected the span tags too... example span style tag i wanted deleted, these tags are purposed to hide text in black colour within the actual chapters and are basically nonsense for copy protection:
ahh but because the text written in the tags are all different for literally every single occurrence, it's hard to delete manually since there are hundreds... also, the epub i'm editing has other span tags with other attributes too which are |
To delete the entrie element, including inner content, use the remove() method. https://developer.mozilla.org/en-US/docs/Web/API/Element/remove Note, if you'd like to see what elements the script is removing, you can add a console.log() command and open the console tab under the developer tools. To select those span elements, you will want to use an attribute selector. https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors So, the CSS should be span[style="color:#000000"] However, the line in the script needs to enclose the CSS in quotes. And the selector has quotes. So, whole script should be let toChange = [...dom.querySelectorAll("span[style=\"color:#000000\"]")];
for(let s of toChange) {
console.log(s);
s.remove();
}
return 0 < toChange.length; Note, I have not tested this script. |
ahhhhh thank you so much again for another explanation, i can now try with other tags with a similar problem! it worked super amazing!! thank you!!! <3 |
hi hiii, i'm here to request for a epubeditor script to mass delete these specific h2, paragraph AND span style tags that appear for every paragraph on the site -- https://exiledrebelsscanlations.com/, from this original request: dteviot/WebToEpub#1040
i just copied the image from the previous issue and pasted it here too for reference!
thank you again! :D
The text was updated successfully, but these errors were encountered: