News for hackers. Stuff that matters.
Re:Show HN: HNCute, a pretty pink Hacker News theme by BugsJustFindMe on Wednesday January 03, 2018 @05:48PM (#16066130)
Why is it a Chrome extension instead of just a bit of CSS in one of the many custom CSS extensions that already abound?
Re:Show HN: HNCute, a pretty pink Hacker News theme by caroherm on Wednesday January 03, 2018 @06:53PM (#16066663)
Mostly because I'm familiar with developing Chrome extensions, and appreciate the freedom and ease of distribution. I also used a bit of Javascript to rework some of the text areas, like the bar at the top. And injecting the favicon is done in JS as well.

I'll look into custom CSS extensions though! I'm not familiar with them. The repo is at https://github.com/carolinehermans/HNcute – it could definitely be organized better, I didn't expect to be sharing!

Re:Show HN: HNCute, a pretty pink Hacker News theme by maddyboo on Wednesday January 03, 2018 @07:00PM (#16066707)
I reaaalllyy like this theme! As others have said, it would be great to have it in the UserStyles library.
Re:Show HN: HNCute, a pretty pink Hacker News theme by caroherm on Wednesday January 03, 2018 @07:23PM (#16066832)
I'll look into it, thanks for the info!
Re:Show HN: HNCute, a pretty pink Hacker News theme by chrismorgan on Thursday January 04, 2018 @02:55AM (#16068696)
You can change the colour of the logo with CSS filters, something like this:

  [href="https://news.ycombinator.com"] > img {
    filter: hue-rotate(-50deg) brightness(150%);
  }
… but that doesn’t fix the favicon.

Some of the other bits done in JS can be done in CSS; this snippet, for example:

  for (let i = 0; i < document.getElementsByTagName("font").length; i++) {
    if (document.getElementsByTagName("font")[i].getAttribute("color") === "#ff6600")
      document.getElementsByTagName("font")[i].setAttribute("color", "#FF83C6")
  }
This is very inefficient (though document.getElementsByTagName is probably O(1) due to its return type HTMLCollection being live, so the end result is probably still only O(n) on the number of <font> elements in the document; it’d be O(n²) with document.querySelectorAll); you should only get the <font> elements once, like this:

  const fontElements = document.getElementsByTagName("font");
  for (let i = 0; i < fontElements.length; i++) {
    if (fontElements[i].getAttribute("color") === "#ff6600")
      fontElements("font")[i].setAttribute("color", "#FF83C6")
  }
It can still be made more efficient, but all I wanted to do was rewrite it in CSS anyway:

  font[color="#ff6600"] {
    color: #ff83c6;
  }
Same deal on the table cells just above it:

  for (let i = 0; i < document.getElementsByTagName("TD").length; i++) {
    if (document.getElementsByTagName("TD")[i].getAttribute("bgcolor") === "#ff6600")
      document.getElementsByTagName("TD")[i].setAttribute("bgcolor", "#fbbfdf")
  }
Use this CSS instead:

  td[bgcolor="#ff6600"] {
    background-color: #fbbfdf;
  }
On the performance matter, a rule of thumb: don’t call getElementsByTagName, getElementsByClassName, querySelector and querySelectorAll more than you absolutely have to. Or anything, really. Cache things in temporary variables aggressively. Take these two lines, for example:

  document.getElementsByClassName("pagetop")[0].innerHTML = document.getElementsByClassName("pagetop")[0].innerHTML.split("|").join(" ")
  document.getElementsByClassName("pagetop")[1].innerHTML = document.getElementsByClassName("pagetop")[1].innerHTML.split("|").join(" ")
You’ve evaluated `document.getElementsByClassName("pagetop")` four times instead of once.

  const pagetops = document.getElementsByClassName("pagetop");
  pagetops[0].innerHTML = pagetops[0].innerHTML.split("|").join(" ")
  pagetops[1].innerHTML = pagetops[1].innerHTML.split("|").join(" ")
Even then, this indexes pagetops twice as often as is necessary, but that operation is quite a bit cheaper than getElementsByClassName. I’d say then to use for..of or forEach or similar, or assign temporaries.
Re:Show HN: HNCute, a pretty pink Hacker News theme by caroherm on Thursday January 04, 2018 @10:12AM (#16070845)
This is EXCELLENT, thank you so much for this. I'm absolutely going to implement these changes.
Re:Show HN: HNCute, a pretty pink Hacker News theme by hultner on Thursday January 04, 2018 @08:10AM (#16070055)
Have you thought about doing a write up on how to build a extension like this for Chrome?

I myself have often been thinking about building a Chrome extension but never gotten around to do it because I'm not sure where to start, something like this seems like a good scope for a first Chrome extension.

Also on a side-note, I checked out your github and saw your foureyes repository, that's a really neat idea I really love that project. You could probably turn that into a business (especially if you build an app for it and sell inbound traffic/affiliate marketing to resellers of glasses/sunglasses).

Re:Show HN: HNCute, a pretty pink Hacker News theme by caroherm on Thursday January 04, 2018 @10:15AM (#16070879)
I've been thinking about doing a writeup, the thing that's holding me back is that there are some pretty good ones out there already, like this one (https://blog.lateral.io/2016/04/create-chrome-extension-modi...)

I'm glad you like foureyes! It was a few years before Warby Parker started doing this: (https://www.engadget.com/2017/11/07/warby-parker-recommends-...)

Re:Show HN: HNCute, a pretty pink Hacker News theme by WorldMaker on Thursday January 04, 2018 @11:32AM (#16071609)
While you are at it, have you considered publishing it to the Firefox and Edge extension stores? Supposedly it is pretty easy to convert a Chrome extension to work in Firefox and Edge these days.

(I'd consider using it on Edge, for at least one user.)

Re:Show HN: HNCute, a pretty pink Hacker News theme by e12e on Wednesday January 03, 2018 @06:38PM (#16066575)
Indeed. Appears the "stylish" extension and/or https://userstyles.org would be a natural fit for this?
Re:Show HN: HNCute, a pretty pink Hacker News theme by smt88 on Wednesday January 03, 2018 @07:53PM (#16067004)
Re:Show HN: HNCute, a pretty pink Hacker News theme by auscompgeek on Wednesday January 03, 2018 @10:42PM (#16067868)
Stylus is the community fork of Stylish from before it was bought out.
Re:Show HN: HNCute, a pretty pink Hacker News theme by ttsda on Wednesday January 03, 2018 @05:50PM (#16066158)
Re:Show HN: HNCute, a pretty pink Hacker News theme by caroherm on Wednesday January 03, 2018 @06:53PM (#16066667)
^^
Re:Show HN: HNCute, a pretty pink Hacker News theme by carlosdp on Wednesday January 03, 2018 @06:45PM (#16066618)
idk, cause the one-click install is easier to distribute than telling people to install a generic plugin they might only use for this 1 mod anyways.
Re:Show HN: HNCute, a pretty pink Hacker News theme by reificator on Wednesday January 03, 2018 @07:15PM (#16066785)
But on the other hand a user who is already interested in overriding the styling for one site is a likely candidate for wanting to install more.

Furthermore, having one extension to trust for security's sake is much nicer than having one for each and every site you want to custom theme. Especially since the general theme is going to want to build up a library of themes and requires user trust to do so, phoning home secret information would eventually destroy that trust. But an extension that only themes Google.com is a more likely candidate for harvesting credentials, for instance.

Creating an extension is also a browser specific process. If there's one browser extension for all sites backed by a repository of plain CSS themes, then users on multiple browsers can benefit from theming with minimal porting effort on the part of the theme author.

Re:Show HN: HNCute, a pretty pink Hacker News theme by Woberto on Wednesday January 03, 2018 @11:25PM (#16068029)
I had no idea it was possible to override site stylings, and though I may look into it, I may not do anything more about it and just keep on accepting sites as they come, even if they're unappealing. So this is a great option - I can change HN to a more pleasant appearance without having to know about the details.

Those are good ideas for improvements, but I'm glad just to have the possibility for change, even if the first draft isn't perfect.

Re:Show HN: HNCute, a pretty pink Hacker News theme by reificator on Wednesday January 03, 2018 @11:51PM (#16068129)
I don't have any issues with that.

But if you do want to learn more, https://userstyles.org is the place to go.