From 429ef5e6284dbc8b07825fb27078eacb12f7b705 Mon Sep 17 00:00:00 2001 From: Matthew Ramina Date: Tue, 2 Jun 2015 20:50:50 -0400 Subject: [PATCH 1/4] Created ScreenResolution, to view your resolution --- lib/DDG/Goodie/ScreenResolution.pm | 39 +++++++++++++++++++ .../screen_resolution/screen_resolution.js | 13 +++++++ t/ScreenResolution.t | 33 ++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 lib/DDG/Goodie/ScreenResolution.pm create mode 100644 share/goodie/screen_resolution/screen_resolution.js create mode 100644 t/ScreenResolution.t diff --git a/lib/DDG/Goodie/ScreenResolution.pm b/lib/DDG/Goodie/ScreenResolution.pm new file mode 100644 index 00000000000..52d54be1a04 --- /dev/null +++ b/lib/DDG/Goodie/ScreenResolution.pm @@ -0,0 +1,39 @@ +package DDG::Goodie::ScreenResolution; +# ABSTRACT: Return the current screen resolution using javascript + +use DDG::Goodie; +use strict; + +zci answer_type => "screen_resolution"; +zci is_cached => 1; + +name "Screen Resolution"; +description "Displays the current screen resolution using javascript"; +primary_example_queries "screen resolution"; +secondary_example_queries "what is my display resolution"; +code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/ScreenResolution.pm"; +attribution twitter => 'mattr555', + github => ['mattr555', 'Matt Ramina']; + +triggers startend => "screen resolution", "display resolution"; + +handle remainder => sub { + return unless $_ eq '' || $_ eq 'what is my'; + + return 'Javascript required', structured_answer => { + id => 'screen_resolution', + name => 'Screen Resolution', + data => { + title => "Your screen resolution is [Loading...]" + }, + templates => { + group => 'text', + item => 0, + options => { + moreAt => 0 + } + } + }; +}; + +1; diff --git a/share/goodie/screen_resolution/screen_resolution.js b/share/goodie/screen_resolution/screen_resolution.js new file mode 100644 index 00000000000..d8e056ff396 --- /dev/null +++ b/share/goodie/screen_resolution/screen_resolution.js @@ -0,0 +1,13 @@ +DDH.screen_resolution = DDH.screen_resolution || {}; + +DDH.screen_resolution.build = function(ops){ + return { + onShow: function(){ + var res = 'Your screen resolution is ' + window.screen.width + 'x' + window.screen.height; + if (window.devicePixelRatio && window.devicePixelRatio > 1){ + res += ' (pixel ratio x' + window.devicePixelRatio + ')'; + } + $('#zci-screen_resolution').find('h3').html(res); + } + } +} \ No newline at end of file diff --git a/t/ScreenResolution.t b/t/ScreenResolution.t new file mode 100644 index 00000000000..3bd107d5326 --- /dev/null +++ b/t/ScreenResolution.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => "screen_resolution"; +zci is_cached => 1; + +my @answer = test_zci('Javascript required', structured_answer => { + id => 'screen_resolution', + name => 'Screen Resolution', + data => { + title => "Your screen resolution is [Loading...]" + }, + templates => { + group => 'text', + item => 0, + options => { + moreAt => 0 + } + } +}); + +ddg_goodie_test( + [qw( DDG::Goodie::ScreenResolution )], + 'screen resolution' => @answer, + 'what is my display resolution' => @answer, + 'blah blah screen resolution' => undef, +); + +done_testing; From 6aef6e830a3594949a29d78faaf9a6b40afa816d Mon Sep 17 00:00:00 2001 From: Matthew Ramina Date: Tue, 2 Jun 2015 22:26:53 -0400 Subject: [PATCH 2/4] ScreenResolution: do insert without DOM --- .../screen_resolution/screen_resolution.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/share/goodie/screen_resolution/screen_resolution.js b/share/goodie/screen_resolution/screen_resolution.js index d8e056ff396..29c13d822a1 100644 --- a/share/goodie/screen_resolution/screen_resolution.js +++ b/share/goodie/screen_resolution/screen_resolution.js @@ -1,13 +1,11 @@ DDH.screen_resolution = DDH.screen_resolution || {}; DDH.screen_resolution.build = function(ops){ - return { - onShow: function(){ - var res = 'Your screen resolution is ' + window.screen.width + 'x' + window.screen.height; - if (window.devicePixelRatio && window.devicePixelRatio > 1){ - res += ' (pixel ratio x' + window.devicePixelRatio + ')'; - } - $('#zci-screen_resolution').find('h3').html(res); - } + var res = 'Your screen resolution is ' + window.screen.width + 'x' + window.screen.height; + if (window.devicePixelRatio && window.devicePixelRatio > 1){ + res += ' (pixel ratio x' + window.devicePixelRatio + ')'; } -} \ No newline at end of file + + ops.data.title = res; + return ops; +} From fcea4b86297618f12a53435425c7ced5e374ca84 Mon Sep 17 00:00:00 2001 From: Matthew Ramina Date: Sun, 21 Jun 2015 14:45:36 -0400 Subject: [PATCH 3/4] ScreenResolution: more triggers --- lib/DDG/Goodie/ScreenResolution.pm | 4 ++-- t/ScreenResolution.t | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/DDG/Goodie/ScreenResolution.pm b/lib/DDG/Goodie/ScreenResolution.pm index 52d54be1a04..8ed8356eede 100644 --- a/lib/DDG/Goodie/ScreenResolution.pm +++ b/lib/DDG/Goodie/ScreenResolution.pm @@ -15,10 +15,10 @@ code_url "https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DD attribution twitter => 'mattr555', github => ['mattr555', 'Matt Ramina']; -triggers startend => "screen resolution", "display resolution"; +triggers startend => "screen resolution", "display resolution", "resolution of my screen"; handle remainder => sub { - return unless $_ eq '' || $_ eq 'what is my'; + return unless /^((what\'?s|what is)?\s?(the|my|current))?$/; return 'Javascript required', structured_answer => { id => 'screen_resolution', diff --git a/t/ScreenResolution.t b/t/ScreenResolution.t index 3bd107d5326..e7d354b771d 100644 --- a/t/ScreenResolution.t +++ b/t/ScreenResolution.t @@ -27,6 +27,10 @@ ddg_goodie_test( [qw( DDG::Goodie::ScreenResolution )], 'screen resolution' => @answer, 'what is my display resolution' => @answer, + 'whats my screen resolution' => @answer, + 'what is my screen resolution' => @answer, + 'what is the resolution of my screen?' => @answer, + 'my screen resolution' => @answer, 'blah blah screen resolution' => undef, ); From c4abe249b7f8970a260aa39763e36629f99cbb66 Mon Sep 17 00:00:00 2001 From: Matthew Ramina Date: Wed, 24 Jun 2015 11:49:05 -0400 Subject: [PATCH 4/4] ScreenResolution: new layout --- lib/DDG/Goodie/ScreenResolution.pm | 4 ++-- share/goodie/screen_resolution/screen_resolution.js | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/DDG/Goodie/ScreenResolution.pm b/lib/DDG/Goodie/ScreenResolution.pm index 8ed8356eede..42bb8935a1c 100644 --- a/lib/DDG/Goodie/ScreenResolution.pm +++ b/lib/DDG/Goodie/ScreenResolution.pm @@ -20,14 +20,14 @@ triggers startend => "screen resolution", "display resolution", "resolution of m handle remainder => sub { return unless /^((what\'?s|what is)?\s?(the|my|current))?$/; - return 'Javascript required', structured_answer => { + return structured_answer => { id => 'screen_resolution', name => 'Screen Resolution', data => { title => "Your screen resolution is [Loading...]" }, templates => { - group => 'text', + group => 'icon', item => 0, options => { moreAt => 0 diff --git a/share/goodie/screen_resolution/screen_resolution.js b/share/goodie/screen_resolution/screen_resolution.js index 29c13d822a1..825b3bd8a91 100644 --- a/share/goodie/screen_resolution/screen_resolution.js +++ b/share/goodie/screen_resolution/screen_resolution.js @@ -1,11 +1,13 @@ DDH.screen_resolution = DDH.screen_resolution || {}; DDH.screen_resolution.build = function(ops){ - var res = 'Your screen resolution is ' + window.screen.width + 'x' + window.screen.height; + var title = window.screen.width + ' × ' + window.screen.height, + sub = ['Your Screen Resolution']; if (window.devicePixelRatio && window.devicePixelRatio > 1){ - res += ' (pixel ratio x' + window.devicePixelRatio + ')'; + sub.push('Pixel Ratio: x' + window.devicePixelRatio); } - ops.data.title = res; + ops.data.title = title; + ops.data.subtitle = sub; return ops; }