Browse Source

cleanup, sw.js improvements

David Walter 3 years ago
parent
commit
48eb729e8a
5 changed files with 295 additions and 209 deletions
  1. 67
    57
      android/.idea/workspace.xml
  2. 2
    0
      web/css/main.css
  3. 13
    10
      web/index.html
  4. 191
    136
      web/js/main.js
  5. 22
    6
      web/sw.js

+ 67
- 57
android/.idea/workspace.xml View File

@@ -80,17 +80,15 @@
80 80
       </file>
81 81
       <file leaf-file-name="activity_lovetester.xml" pinned="false" current-in-tab="true">
82 82
         <entry file="file://$PROJECT_DIR$/app/src/main/res/layout/activity_lovetester.xml">
83
-          <provider editor-type-id="android-designer2">
84
-            <state />
85
-          </provider>
86 83
           <provider selected="true" editor-type-id="text-editor">
87
-            <state relative-caret-position="135">
84
+            <state relative-caret-position="1905">
88 85
               <caret line="127" column="4" selection-start-line="127" selection-start-column="4" selection-end-line="138" selection-end-column="40" />
89
-              <folding>
90
-                <element signature="e#2144#2163#0" expanded="true" />
91
-              </folding>
86
+              <folding />
92 87
             </state>
93 88
           </provider>
89
+          <provider editor-type-id="android-designer2">
90
+            <state />
91
+          </provider>
94 92
         </entry>
95 93
       </file>
96 94
       <file leaf-file-name="strings.xml" pinned="false" current-in-tab="false">
@@ -2296,8 +2294,9 @@
2296 2294
     </option>
2297 2295
   </component>
2298 2296
   <component name="ProjectFrameBounds">
2297
+    <option name="y" value="23" />
2299 2298
     <option name="width" value="1280" />
2300
-    <option name="height" value="800" />
2299
+    <option name="height" value="732" />
2301 2300
   </component>
2302 2301
   <component name="ProjectLevelVcsManager" settingsEditedManually="false">
2303 2302
     <OptionsSetting value="true" id="Add" />
@@ -2472,7 +2471,6 @@
2472 2471
   <component name="PropertiesComponent">
2473 2472
     <property name="settings.editor.selected.configurable" value="reference.settingsdialog.IDE.editor.colors" />
2474 2473
     <property name="settings.editor.splitter.proportion" value="0.2" />
2475
-    <property name="FullScreen" value="true" />
2476 2474
   </component>
2477 2475
   <component name="RunManager" selected="Android App.app">
2478 2476
     <configuration default="true" type="AndroidJUnit" factoryName="Android JUnit">
@@ -2797,17 +2795,16 @@
2797 2795
     <servers />
2798 2796
   </component>
2799 2797
   <component name="ToolWindowManager">
2800
-    <frame x="0" y="0" width="1280" height="800" extended-state="0" />
2801
-    <editor active="true" />
2798
+    <frame x="0" y="23" width="1280" height="732" extended-state="6" />
2799
+    <editor active="false" />
2802 2800
     <layout>
2803 2801
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
2804
-      <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.26912183" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
2802
+      <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.26912183" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
2805 2803
       <window_info id="Build Variants" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="true" content_ui="tabs" />
2806 2804
       <window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
2807 2805
       <window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
2808 2806
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
2809 2807
       <window_info id="Android Monitor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
2810
-      <window_info id="Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32956383" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
2811 2808
       <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
2812 2809
       <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
2813 2810
       <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@@ -2827,6 +2824,7 @@
2827 2824
       <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
2828 2825
       <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
2829 2826
       <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
2827
+      <window_info id="Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32956383" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
2830 2828
       <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
2831 2829
     </layout>
2832 2830
   </component>
@@ -2846,15 +2844,61 @@
2846 2844
     <watches-manager />
2847 2845
   </component>
2848 2846
   <component name="editorHistoryManager">
2847
+    <entry file="file://$PROJECT_DIR$/build.gradle">
2848
+      <provider selected="true" editor-type-id="text-editor">
2849
+        <state relative-caret-position="0">
2850
+          <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2851
+          <folding />
2852
+        </state>
2853
+      </provider>
2854
+    </entry>
2855
+    <entry file="file://$PROJECT_DIR$/android.iml">
2856
+      <provider selected="true" editor-type-id="text-editor">
2857
+        <state relative-caret-position="0">
2858
+          <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2859
+          <folding />
2860
+        </state>
2861
+      </provider>
2862
+    </entry>
2863
+    <entry file="file://$PROJECT_DIR$/app/build.gradle">
2864
+      <provider selected="true" editor-type-id="text-editor">
2865
+        <state relative-caret-position="195">
2866
+          <caret line="13" column="16" selection-start-line="13" selection-start-column="16" selection-end-line="13" selection-end-column="16" />
2867
+          <folding />
2868
+        </state>
2869
+      </provider>
2870
+    </entry>
2871
+    <entry file="file://$PROJECT_DIR$/app/src/main/java/at/davidwalter/lovetester/LoveClass.java">
2872
+      <provider selected="true" editor-type-id="text-editor">
2873
+        <state relative-caret-position="555">
2874
+          <caret line="37" column="23" selection-start-line="37" selection-start-column="23" selection-end-line="37" selection-end-column="23" />
2875
+          <folding />
2876
+        </state>
2877
+      </provider>
2878
+    </entry>
2879
+    <entry file="file://$PROJECT_DIR$/app/src/main/res/layout/activity_lovetester.xml">
2880
+      <provider selected="true" editor-type-id="text-editor">
2881
+        <state relative-caret-position="1905">
2882
+          <caret line="127" column="4" selection-start-line="127" selection-start-column="4" selection-end-line="138" selection-end-column="40" />
2883
+          <folding />
2884
+        </state>
2885
+      </provider>
2886
+      <provider editor-type-id="android-designer2">
2887
+        <state />
2888
+      </provider>
2889
+    </entry>
2890
+    <entry file="file://$PROJECT_DIR$/app/src/main/res/values/strings.xml">
2891
+      <provider selected="true" editor-type-id="text-editor">
2892
+        <state relative-caret-position="255">
2893
+          <caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
2894
+          <folding />
2895
+        </state>
2896
+      </provider>
2897
+    </entry>
2849 2898
     <entry file="file://$PROJECT_DIR$/app/src/androidTest/java/at/davidwalter/lovetester/ApplicationTest.java">
2850 2899
       <provider selected="true" editor-type-id="text-editor">
2851 2900
         <state relative-caret-position="0">
2852 2901
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2853
-          <folding>
2854
-            <element signature="imports" expanded="false" />
2855
-            <element signature="e#313#314#0" expanded="false" />
2856
-            <element signature="e#353#354#0" expanded="false" />
2857
-          </folding>
2858 2902
         </state>
2859 2903
       </provider>
2860 2904
     </entry>
@@ -2862,11 +2906,6 @@
2862 2906
       <provider selected="true" editor-type-id="text-editor">
2863 2907
         <state relative-caret-position="0">
2864 2908
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2865
-          <folding>
2866
-            <element signature="imports" expanded="false" />
2867
-            <element signature="e#1004#1005#0" expanded="false" />
2868
-            <element signature="e#1044#1045#0" expanded="false" />
2869
-          </folding>
2870 2909
         </state>
2871 2910
       </provider>
2872 2911
     </entry>
@@ -2874,9 +2913,6 @@
2874 2913
       <provider selected="true" editor-type-id="text-editor">
2875 2914
         <state relative-caret-position="0">
2876 2915
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2877
-          <folding>
2878
-            <element signature="imports" expanded="false" />
2879
-          </folding>
2880 2916
         </state>
2881 2917
       </provider>
2882 2918
     </entry>
@@ -2900,7 +2936,6 @@
2900 2936
       <provider selected="true" editor-type-id="text-editor">
2901 2937
         <state relative-caret-position="0">
2902 2938
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2903
-          <folding />
2904 2939
         </state>
2905 2940
       </provider>
2906 2941
     </entry>
@@ -2908,11 +2943,6 @@
2908 2943
       <provider selected="true" editor-type-id="text-editor">
2909 2944
         <state relative-caret-position="0">
2910 2945
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2911
-          <folding>
2912
-            <element signature="imports" expanded="false" />
2913
-            <element signature="e#1004#1005#0" expanded="false" />
2914
-            <element signature="e#1044#1045#0" expanded="false" />
2915
-          </folding>
2916 2946
         </state>
2917 2947
       </provider>
2918 2948
     </entry>
@@ -2920,9 +2950,6 @@
2920 2950
       <provider selected="true" editor-type-id="text-editor">
2921 2951
         <state relative-caret-position="0">
2922 2952
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2923
-          <folding>
2924
-            <element signature="imports" expanded="false" />
2925
-          </folding>
2926 2953
         </state>
2927 2954
       </provider>
2928 2955
     </entry>
@@ -2941,7 +2968,6 @@
2941 2968
       <provider selected="true" editor-type-id="text-editor">
2942 2969
         <state relative-caret-position="0">
2943 2970
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2944
-          <folding />
2945 2971
         </state>
2946 2972
       </provider>
2947 2973
     </entry>
@@ -2949,11 +2975,6 @@
2949 2975
       <provider selected="true" editor-type-id="text-editor">
2950 2976
         <state relative-caret-position="135">
2951 2977
           <caret line="12" column="1" selection-start-line="12" selection-start-column="1" selection-end-line="12" selection-end-column="1" />
2952
-          <folding>
2953
-            <element signature="imports" expanded="false" />
2954
-            <element signature="e#313#314#0" expanded="false" />
2955
-            <element signature="e#353#354#0" expanded="false" />
2956
-          </folding>
2957 2978
         </state>
2958 2979
       </provider>
2959 2980
     </entry>
@@ -2961,7 +2982,6 @@
2961 2982
       <provider selected="true" editor-type-id="text-editor">
2962 2983
         <state relative-caret-position="90">
2963 2984
           <caret line="6" column="0" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" />
2964
-          <folding />
2965 2985
         </state>
2966 2986
       </provider>
2967 2987
     </entry>
@@ -2969,7 +2989,6 @@
2969 2989
       <provider selected="true" editor-type-id="text-editor">
2970 2990
         <state relative-caret-position="0">
2971 2991
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2972
-          <folding />
2973 2992
         </state>
2974 2993
       </provider>
2975 2994
     </entry>
@@ -2977,7 +2996,6 @@
2977 2996
       <provider selected="true" editor-type-id="text-editor">
2978 2997
         <state relative-caret-position="0">
2979 2998
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2980
-          <folding />
2981 2999
         </state>
2982 3000
       </provider>
2983 3001
     </entry>
@@ -2985,7 +3003,6 @@
2985 3003
       <provider selected="true" editor-type-id="text-editor">
2986 3004
         <state relative-caret-position="0">
2987 3005
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2988
-          <folding />
2989 3006
         </state>
2990 3007
       </provider>
2991 3008
     </entry>
@@ -2993,7 +3010,6 @@
2993 3010
       <provider selected="true" editor-type-id="text-editor">
2994 3011
         <state relative-caret-position="0">
2995 3012
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
2996
-          <folding />
2997 3013
         </state>
2998 3014
       </provider>
2999 3015
     </entry>
@@ -3001,7 +3017,6 @@
3001 3017
       <provider selected="true" editor-type-id="text-editor">
3002 3018
         <state relative-caret-position="-1722">
3003 3019
           <caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
3004
-          <folding />
3005 3020
         </state>
3006 3021
       </provider>
3007 3022
     </entry>
@@ -3009,7 +3024,6 @@
3009 3024
       <provider selected="true" editor-type-id="text-editor">
3010 3025
         <state relative-caret-position="0">
3011 3026
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
3012
-          <folding />
3013 3027
         </state>
3014 3028
       </provider>
3015 3029
     </entry>
@@ -3017,7 +3031,6 @@
3017 3031
       <provider selected="true" editor-type-id="text-editor">
3018 3032
         <state relative-caret-position="239">
3019 3033
           <caret line="28" column="63" selection-start-line="28" selection-start-column="63" selection-end-line="28" selection-end-column="63" />
3020
-          <folding />
3021 3034
         </state>
3022 3035
       </provider>
3023 3036
     </entry>
@@ -3025,7 +3038,6 @@
3025 3038
       <provider selected="true" editor-type-id="text-editor">
3026 3039
         <state relative-caret-position="-555">
3027 3040
           <caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
3028
-          <folding />
3029 3041
         </state>
3030 3042
       </provider>
3031 3043
     </entry>
@@ -3070,17 +3082,15 @@
3070 3082
       </provider>
3071 3083
     </entry>
3072 3084
     <entry file="file://$PROJECT_DIR$/app/src/main/res/layout/activity_lovetester.xml">
3073
-      <provider editor-type-id="android-designer2">
3074
-        <state />
3075
-      </provider>
3076 3085
       <provider selected="true" editor-type-id="text-editor">
3077
-        <state relative-caret-position="135">
3086
+        <state relative-caret-position="1905">
3078 3087
           <caret line="127" column="4" selection-start-line="127" selection-start-column="4" selection-end-line="138" selection-end-column="40" />
3079
-          <folding>
3080
-            <element signature="e#2144#2163#0" expanded="true" />
3081
-          </folding>
3088
+          <folding />
3082 3089
         </state>
3083 3090
       </provider>
3091
+      <provider editor-type-id="android-designer2">
3092
+        <state />
3093
+      </provider>
3084 3094
     </entry>
3085 3095
   </component>
3086 3096
 </project>

+ 2
- 0
web/css/main.css View File

@@ -1,4 +1,5 @@
1 1
 #love-input, #love-output {
2
+	display: none;
2 3
 	transition: diplay 1s linear;
3 4
 }
4 5
 
@@ -36,6 +37,7 @@ header > .menu {
36 37
 }
37 38
 
38 39
 header>.navigation {
40
+	display: none;
39 41
 	float: left;
40 42
 	position: absolute;
41 43
 	left: 1em;

+ 13
- 10
web/index.html View File

@@ -8,10 +8,6 @@
8 8
 	<link type="text/css" rel="stylesheet" href="css/font-awesome.min.css" />
9 9
 	<link type="text/css" rel="stylesheet" href="css/main.css" />
10 10
 
11
-	<script type="text/javascript" src="js/jquery.min.js"></script>
12
-	<script type="text/javascript" src="js/jquery.cookie.js"></script>
13
-	<script type="text/javascript" src="js/main.js"></script>
14
-
15 11
 	<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png" />
16 12
 	<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png" />
17 13
 	<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png" />
@@ -31,14 +27,13 @@
31 27
 	<header class="">
32 28
 		<a class="navigation" href="javascript:history.back()"><i class="fa fa-arrow-left" aria-hidden="true"></i></a>
33 29
 		<p>Lovetester</p>
34
-		<ul class="menu">
35
-			<li class="share" onclick="share()"><i class="fa fa-share" aria-hidden="true"></i></li>
30
+		<!--ul class="menu">
36 31
 			<li><i class="fa fa-question-circle" aria-hidden="true"></i></li>
37
-		</ul>
32
+		</ul>-->
38 33
 	</header>
39 34
 	<main>
40 35
 		<div>
41
-			<form id="love-input" class="" method="get" accept-charset="UTF-8">
36
+			<form id="love-input" method="get" accept-charset="UTF-8">
42 37
 				<div class="element">
43 38
 					<span id="genderYou"><i onclick="genderYouClick('female')" class="fa fa-venus gender" aria-hidden="true"></i></span>
44 39
 					<input id="you" name="you" type="text" placeholder="Your name" required/>
@@ -61,8 +56,12 @@
61 56
 				<input id="restart" class="button" type="submit" value="Restart" />
62 57
 			</form>
63 58
 		</div>
64
-		<img class="heart left" src="img/heart_left.png">
65
-		<img class="heart right" src="img/heart_right.png">
59
+		<picture>
60
+			<img class="heart left" src="img/heart_left.png" alt="Heart left">
61
+		</picture>
62
+		<picture>
63
+			<img class="heart right" src="img/heart_right.png" alt="Heart right">
64
+		</picture>
66 65
 	</main>
67 66
 	<footer>
68 67
 		<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
@@ -72,6 +71,10 @@
72 71
 			(adsbygoogle = window.adsbygoogle || []).push({});
73 72
 		</script>
74 73
 	</footer>
74
+
75
+	<script type="text/javascript" src="js/jquery.min.js"></script>
76
+	<script type="text/javascript" src="js/jquery.cookie.js"></script>
77
+	<script type="text/javascript" src="js/main.js"></script>
75 78
 </body>
76 79
 
77 80
 </html>

+ 191
- 136
web/js/main.js View File

@@ -1,131 +1,266 @@
1
+function $_GET(param) {
2
+	var vars = {}
3
+	window.location.href.replace(location.hash, '').replace(
4
+		/[?&]+([^=&]+)=?([^&]*)?/gi,
5
+		function(m, key, value) {
6
+			vars[key] = value !== undefined ? value.replace('+', ' ') : ''
7
+		}
8
+	)
9
+
10
+	if (param) {
11
+		return vars[param] ? decodeURIComponent(vars[param]) : null
12
+	}
13
+	return vars
14
+}
15
+
16
+function genderYouClick(value) {
17
+	if (value == "female") {
18
+		value = "male"
19
+	} else {
20
+		value = "female"
21
+	}
22
+
23
+	setGender('genderYou', value)
24
+	$.cookie('genderYou', value, {
25
+		expires: 365
26
+	})
27
+
28
+	AnimateRotate('genderYou', 360)
29
+}
30
+
31
+function genderOtherClick(value) {
32
+	if (value == "female") {
33
+		value = "male"
34
+	} else {
35
+		value = "female"
36
+	}
37
+
38
+	setGender('genderOther', value)
39
+	$.cookie('genderOther', value, {
40
+		expires: 365
41
+	})
42
+
43
+	AnimateRotate('genderOther', 360)
44
+}
45
+
46
+function AnimateRotate(selector, angle) {
47
+	var $elem = $("#" + selector)
48
+
49
+	$({
50
+		deg: 0
51
+	}).animate({
52
+		deg: angle
53
+	}, {
54
+		duration: 500,
55
+		step: function(now) {
56
+			$elem.css({
57
+				transform: 'rotate(' + now + 'deg)'
58
+			})
59
+		}
60
+	})
61
+}
62
+
63
+function setGender(selector, value) {
64
+	if (value == "male") {
65
+		$("#" + selector).html('<i onclick="' + selector + 'Click(\'' + value + '\')" class="fa fa-mars gender" aria-hidden="true"></i>')
66
+	} else if (value == "female") {
67
+		$("#" + selector).html('<i  onclick="' + selector + 'Click(\'' + value + '\')" class="fa fa-venus gender" aria-hidden="true"></i>')
68
+	}
69
+
70
+	if (selector == "genderOther") {
71
+		$('#other').attr('placeholder', value == "male" ? 'His name' : 'Her name')
72
+	}
73
+}
74
+
75
+function clearInput(selector) {
76
+	$("#" + selector).val("")
77
+	$("#" + selector).focus()
78
+}
79
+
80
+function main() {
81
+	if ('serviceWorker' in navigator) {
82
+		window.addEventListener('load', function() {
83
+			navigator.serviceWorker.register('sw.js').then(function(registration) {
84
+				// Registration was successful
85
+				console.log('ServiceWorker registration successful with scope: ', registration.scope)
86
+			}, function(err) {
87
+				// registration failed :(
88
+				console.log('ServiceWorker registration failed: ', err)
89
+			})
90
+		})
91
+	}
92
+
93
+	setGender("genderYou", $.cookie("genderYou"))
94
+	setGender("genderOther", $.cookie("genderOther"))
95
+
96
+
97
+	if (navigator.share !== undefined) {
98
+		$(".share").css('display', 'inline')
99
+	}
100
+
101
+	var you = $_GET('you')
102
+	var other = $_GET('other')
103
+
104
+	if (you && other) {
105
+		$("#love-output").css('display', 'block')
106
+		$(".navigation").css('display', 'inline')
107
+		
108
+		$("title").html('Lovetester - ' + you + ' &#9829 ' + other)
109
+		$("#names").html(you + ' <i class="fa fa-heart red" aria-hidden="true"></i> ' + other)
110
+
111
+		animateLove(love(you, other))
112
+	} else {
113
+		$("#love-input").css('display', 'block')
114
+	}
115
+}
116
+
117
+function share() {
118
+	var shareUrl = document.querySelector('link[rel=canonical]') ? document.querySelector('link[rel=canonical]').href : window.location.href
119
+
120
+	if (navigator.share !== undefined) {
121
+		// Share the resource
122
+		navigator.share({
123
+				title: document.title,
124
+				url: shareUrl
125
+			}).then(() => console.log('Successful share'))
126
+			.catch((error) => console.log('Error sharing:', error))
127
+	}
128
+}
129
+
130
+$(document).ready(main)
131
+
132
+/*
133
+ * Love
134
+ */
135
+
1 136
 function love(you, other) {
2
-	var love = 0;
137
+	var love = 0
3 138
 
4
-	var equalCharacters = getEqualCharacters(you, other);
139
+	var equalCharacters = getEqualCharacters(you, other)
5 140
 
6
-	var value1 = getChecksum(you) * equalCharacters * you.length * getCharactersum(you);
7
-	var value2 = getChecksum(other) * equalCharacters * other.length * getCharactersum(other);
141
+	var value1 = getChecksum(you) * equalCharacters * you.length * getCharactersum(you)
142
+	var value2 = getChecksum(other) * equalCharacters * other.length * getCharactersum(other)
8 143
 
9 144
 	if (value1 != 0 && value2 != 0) {
10
-		love = Math.trunc(Math.PI * Math.E * (value1 * value2) / (value1 + value2)) % 100;
145
+		love = Math.trunc(Math.PI * Math.E * (value1 * value2) / (value1 + value2)) % 100
11 146
 	}
12 147
 
13
-	return love;
148
+	return love
14 149
 }
15 150
 
16 151
 function getEqualCharacters(you, other) {
17
-	var equals = 0;
152
+	var equals = 0
18 153
 
19
-	you = you.toLowerCase();
20
-	other = other.toLowerCase();
154
+	you = you.toLowerCase()
155
+	other = other.toLowerCase()
21 156
 
22 157
 	for (var i = 0; i < you.length; i += 1) {
23 158
 		for (var j = 0; j < you.length; j += 1) {
24 159
 			if (you.charAt(i) == other.charAt(j)) {
25
-				equals += 1;
160
+				equals += 1
26 161
 			}
27 162
 		}
28 163
 	}
29 164
 
30 165
 	if (equals == 0) {
31
-		equals = 1;
166
+		equals = 1
32 167
 	}
33
-	return equals;
168
+	return equals
34 169
 }
35 170
 
36 171
 function getChecksum(name) {
37
-	var e = 0;
172
+	var e = 0
38 173
 
39
-	name = name.toLowerCase();
174
+	name = name.toLowerCase()
40 175
 
41 176
 	for (var i = 0; i < name.length; i += 1) {
42
-		var compare = name.charAt(i);
43
-
44
-		if (compare == 'a' || compare == 'j' || compare == 's') e += 1;
45
-		else if (compare == 'b' || compare == 'k' || compare == 't') e += 2;
46
-		else if (compare == 'c' || compare == 'l' || compare == 'u') e += 3;
47
-		else if (compare == 'd' || compare == 'm' || compare == 'v') e += 4;
48
-		else if (compare == 'e' || compare == 'n' || compare == 'w') e += 5;
49
-		else if (compare == 'f' || compare == 'o' || compare == 'x') e += 6;
50
-		else if (compare == 'g' || compare == 'p' || compare == 'y') e += 7;
51
-		else if (compare == 'h' || compare == 'q' || compare == 'z') e += 8;
52
-		else if (compare == 'i' || compare == 'r') e += 9;
177
+		var compare = name.charAt(i)
178
+
179
+		if (compare == 'a' || compare == 'j' || compare == 's') e += 1
180
+		else if (compare == 'b' || compare == 'k' || compare == 't') e += 2
181
+		else if (compare == 'c' || compare == 'l' || compare == 'u') e += 3
182
+		else if (compare == 'd' || compare == 'm' || compare == 'v') e += 4
183
+		else if (compare == 'e' || compare == 'n' || compare == 'w') e += 5
184
+		else if (compare == 'f' || compare == 'o' || compare == 'x') e += 6
185
+		else if (compare == 'g' || compare == 'p' || compare == 'y') e += 7
186
+		else if (compare == 'h' || compare == 'q' || compare == 'z') e += 8
187
+		else if (compare == 'i' || compare == 'r') e += 9
53 188
 	}
54 189
 
55 190
 	if (e > 10) {
56
-		var tempSum = e;
57
-		var temp = 0;
191
+		var tempSum = e
192
+		var temp = 0
58 193
 
59 194
 		while (tempSum > 0) {
60
-			temp += tempSum % 10;
61
-			tempSum = Math.trunc(tempSum / 10);
195
+			temp += tempSum % 10
196
+			tempSum = Math.trunc(tempSum / 10)
62 197
 		}
63 198
 
64
-		e = temp;
199
+		e = temp
65 200
 	}
66 201
 
67
-	return Math.trunc(e);
202
+	return Math.trunc(e)
68 203
 }
69 204
 
70 205
 function getCharactersum(name) {
71
-	var e = 0;
206
+	var e = 0
72 207
 
73
-	name = name.toLowerCase();
208
+	name = name.toLowerCase()
74 209
 
75 210
 	for (var i = 0; i < name.length; i += 1) {
76
-		e += Math.trunc(name.charCodeAt(i) / (i + 1));
211
+		e += Math.trunc(name.charCodeAt(i) / (i + 1))
77 212
 	}
78 213
 
79
-	return Math.trunc(e);
214
+	return Math.trunc(e)
80 215
 }
81 216
 
82 217
 function $_GET(param) {
83
-	var vars = {};
218
+	var vars = {}
84 219
 	window.location.href.replace(location.hash, '').replace(
85 220
 		/[?&]+([^=&]+)=?([^&]*)?/gi,
86 221
 		function(m, key, value) {
87
-			vars[key] = value !== undefined ? value.replace('+', ' ') : '';
222
+			vars[key] = value !== undefined ? value.replace('+', ' ') : ''
88 223
 		}
89
-	);
224
+	)
90 225
 
91 226
 	if (param) {
92
-		return vars[param] ? decodeURIComponent(vars[param]) : null;
227
+		return vars[param] ? decodeURIComponent(vars[param]) : null
93 228
 	}
94
-	return vars;
229
+	return vars
95 230
 }
96 231
 
97 232
 function genderYouClick(value) {
98 233
 	if (value == "female") {
99
-		value = "male";
234
+		value = "male"
100 235
 	} else {
101
-		value = "female";
236
+		value = "female"
102 237
 	}
103 238
 
104
-	setGender('genderYou', value);
239
+	setGender('genderYou', value)
105 240
 	$.cookie('genderYou', value, {
106 241
 		expires: 365
107
-	});
242
+	})
108 243
 
109
-	AnimateRotate('genderYou', 360);
244
+	AnimateRotate('genderYou', 360)
110 245
 }
111 246
 
112 247
 function genderOtherClick(value) {
113 248
 	if (value == "female") {
114
-		value = "male";
249
+		value = "male"
115 250
 	} else {
116
-		value = "female";
251
+		value = "female"
117 252
 	}
118 253
 
119
-	setGender('genderOther', value);
254
+	setGender('genderOther', value)
120 255
 	$.cookie('genderOther', value, {
121 256
 		expires: 365
122
-	});
257
+	})
123 258
 
124
-	AnimateRotate('genderOther', 360);
259
+	AnimateRotate('genderOther', 360)
125 260
 }
126 261
 
127 262
 function AnimateRotate(selector, angle) {
128
-	var $elem = $("#" + selector);
263
+	var $elem = $("#" + selector)
129 264
 
130 265
 	$({
131 266
 		deg: 0
@@ -136,27 +271,9 @@ function AnimateRotate(selector, angle) {
136 271
 		step: function(now) {
137 272
 			$elem.css({
138 273
 				transform: 'rotate(' + now + 'deg)'
139
-			});
274
+			})
140 275
 		}
141
-	});
142
-}
143
-
144
-function setGender(selector, value) {
145
-	if (value == "male") {
146
-		$("#" + selector).html('<i onclick="' + selector + 'Click(\'' + value + '\')" class="fa fa-mars gender" aria-hidden="true"></i>');
147
-	} else if (value == "female") {
148
-		$("#" + selector).html('<i  onclick="' + selector + 'Click(\'' + value + '\')" class="fa fa-venus gender" aria-hidden="true"></i>');
149
-	}
150
-
151
-	if (selector == "genderOther") {
152
-		$('#other').attr('placeholder', value == "male" ? 'His name' : 'Her name');
153
-	}
154
-}
155
-
156
-function clearInput(selector) {
157
-	console.log(selector);
158
-	$("#" + selector).val("");
159
-	$("#" + selector).focus();
276
+	})
160 277
 }
161 278
 
162 279
 function animateLove(value) {
@@ -167,69 +284,7 @@ function animateLove(value) {
167 284
 	}, {
168 285
 		duration: 500,
169 286
 		step: function(now) {
170
-			console.log(now)
171
-			$("#result").text(Math.floor(now) + " %");
287
+			$("#result").text(Math.floor(now) + " %")
172 288
 		}
173
-	});
174
-}
175
-
176
-function main() {
177
-	if ('serviceWorker' in navigator) {
178
-		window.addEventListener('load', function() {
179
-			navigator.serviceWorker.register('sw.js').then(function(registration) {
180
-				// Registration was successful
181
-				console.log('ServiceWorker registration successful with scope: ', registration.scope);
182
-			}, function(err) {
183
-				// registration failed :(
184
-				console.log('ServiceWorker registration failed: ', err);
185
-			});
186
-		});
187
-	}
188
-	
189
-	if (navigator.share === undefined) {
190
-		$(".share").css('display', 'none')
191
-	}
192
-
193
-	setGender("genderYou", $.cookie("genderYou"));
194
-	setGender("genderOther", $.cookie("genderOther"));
195
-
196
-	var you = $_GET('you');
197
-	var other = $_GET('other');
198
-	if (you && other) {
199
-		$("#love-output").css('display', 'block');
200
-		$("#love-input").css('display', 'none');
201
-
202
-		$("title").html('Lovetester - ' + you + ' &#9829 ' + other);
203
-		$("#names").html(you + ' <i class="fa fa-heart red" aria-hidden="true"></i> ' + other);
204
-		
205
-		if (navigator.share === undefined) {
206
-			$(".share").css('display', 'none')
207
-		} else {
208
-			$(".share").css('display', 'inline')
209
-		}
210
-		
211
-		animateLove(love(you, other));
212
-	} else {
213
-		$("#love-input").css('display', 'block');
214
-		$("#love-output").css('display', 'none');
215
-
216
-		$(".navigation").css('display', 'none');
217
-		
218
-		$(".share").css('display', 'none')
219
-	}
220
-}
221
-
222
-function share() {
223
-	var shareUrl = document.querySelector('link[rel=canonical]') ? document.querySelector('link[rel=canonical]').href : window.location.href;
224
-	
225
-	if (navigator.share !== undefined) {
226
-		// Share the resource
227
-		navigator.share({
228
-				title: document.title,
229
-				url: shareUrl
230
-			}).then(() => console.log('Successful share'))
231
-			.catch((error) => console.log('Error sharing:', error));
232
-	}
233
-}
234
-
235
-$(document).ready(main);
289
+	})
290
+}

+ 22
- 6
web/sw.js View File

@@ -1,6 +1,7 @@
1
-var CACHE_NAME = 'lovetester-cache-v2';
1
+var CACHE_NAME = 'lovetester-cache-v2'
2 2
 var urlsToCache = [
3 3
 	'/lovetester/',
4
+	'/lovetester/?',
4 5
 	'/lovetester/manifest.json',
5 6
 	'/lovetester/favicon.ico',
6 7
 	'/lovetester/index.html',
@@ -20,15 +21,30 @@ var urlsToCache = [
20 21
 	'/lovetester/fonts/fontawesome-webfont.woff2?v=4.7.0',
21 22
 	'/lovetester/img/heart_left.png',
22 23
 	'/lovetester/img/heart_right.png'
23
-];
24
+]
24 25
 
25 26
 self.addEventListener('install', function(event) {
26 27
 	// Perform install steps
27 28
 	event.waitUntil(
28 29
 		caches.open(CACHE_NAME)
29 30
 		.then(function(cache) {
30
-			console.log('Opened cache');
31
-			return cache.addAll(urlsToCache);
31
+			return cache.addAll(urlsToCache)
32 32
 		})
33
-	);
34
-});
33
+	)
34
+})
35
+
36
+self.addEventListener('fetch', function(event) {
37
+	console.log(event.request.url)
38
+	event.respondWith(
39
+		caches.match(event.request).then(function(response) {
40
+			if (response) {
41
+				return response
42
+			} else if (event.request.url.includes('/lovetester/?')) {
43
+				return caches.match("/lovetester/index.html").then(function(response) {
44
+					return response || fetch(event.request)
45
+				})
46
+			}
47
+			return fetch(event.request)
48
+		})
49
+	)
50
+})