Skip to content

Instantly share code, notes, and snippets.

@kuy
Last active March 10, 2016 15:01
Show Gist options
  • Save kuy/66f94ac7dfc4f7b69a43 to your computer and use it in GitHub Desktop.
Save kuy/66f94ac7dfc4f7b69a43 to your computer and use it in GitHub Desktop.
Qiita Post Freshness
// ==UserScript==
// @name Qiita Post Freshness
// @namespace http://endflow.net/
// @version 0.1
// @description changes background color of header based on post's freshness.
// @author You
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @require https://d3js.org/d3.v4.0.0-alpha.28.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js
// @match http://qiita.com/*/items/*
// ==/UserScript==
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext:true */
const start = moment().subtract(6, 'months').toDate();
const end = moment().subtract(1, 'week').toDate();
const scale = d3.scaleLinear().domain([start, end]).range(['#152B04', '#79b74a']).clamp(true);
const el = document.querySelector('time[itemprop="datePublished"]');
const postDate = new Date(el.getAttribute('datetime'));
const target = document.querySelector('.itemsShowHeader');
target.style.backgroundColor = scale(postDate);
/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment