Greasy Fork is available in English.

讨论 » 创建请求

Date highlight

§
发表于:2018-01-01

Date highlight

Possible to get a script that will find a date in the format below and give time since that date?
2016-12-18

Would then be:
2016-12-18 -- 1 year 11 days

Side note if that is to much can some give an example of how to discover a date older than seven days? I have a regex that discovers the date fine, just not sure on how to take it and see if it is older than.

§
发表于:2018-01-02
编辑于:2018-01-02

Something along the lines of this?

let stringWithDate = "Search this string for the date 2016-12-18 and find out if it is older than 7 days";

// Adjust regex as needed, this only searches for xxxx-(x)x-(x)x
let dateSearch = /\b(\d{4})-(\d{1,2})-(\d{1,2})\b/g;
let firstDate = dateSearch.exec(stringWithDate);

let date = new Date(firstDate[1], firstDate[2]-1, firstDate[3]);
let timeSinceDate = Date.now() - date; // timeSinceDate is in milliseconds
let overWeekOld = timeSinceDate > (1000 * 60 * 60 * 24 * 7);
§
发表于:2018-01-03

Not able to get it to work.

§
发表于:2018-01-03

Without knowing what specifically isn't working, there isn't really any way for me to help you further, sorry.

§
发表于:2018-01-03

Sorry about that I should know better and be more descriptive.

Load script. Goto pages that have the date that I would like to check. Nothing happens.

Nothing happens on this page either. When you run the script what does it show when you see: 2018-01-01

§
发表于:2018-01-03

Sorry, you asked for an example to check if a date is older than 7 days, so this was just an example snippet. I wasn't providing a complete script, because I thought you implied that you already had most of the script and just needed an example to complete it.

发表回复

登录以发表回复。