nblog_zon 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nblog_zon.rb +337 -213
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 315f0c0d217ec2619872a913f0f11b9fe8c4040238871fae91484a7c603efba4
4
- data.tar.gz: af972f66ca97047e365e4ddbcc80eb8ce40ce0c2d7909eaf0500434f799e3c51
3
+ metadata.gz: 5afd5e1aeacd5f7c0f4efd5f46afaf99c03040e5bbd654cf9d19b8ac2ef2c7d2
4
+ data.tar.gz: 8709907dccd6869df05ffe64d18df8b0478164bc9dfa0b26463f6d85b0ba6063
5
5
  SHA512:
6
- metadata.gz: 511b145bce7485e76a8229a9665efb0c12a526d0fb40b2a7d8414e7d94c4937a0c02eb74eb4da389be853f3d5337976e7b22fef9e0a78a3c5e522af2fca40138
7
- data.tar.gz: 6cca527f19b9ae1bd52d75e8895922effd526d743d8930978f7ae4c2594c07a29e87f6834689c0ac623205ca3e70a21f2d69be1b75a121dfb494b17e55b16c69
6
+ metadata.gz: 5cefb322633f235adf3bc291ddae95de794eb6665b9c0d89cfdcc502c78e44f86e8e827758eb1cfd4042b254a009f8d4a687b8a69adc4901dbe02c3bb3761bb8
7
+ data.tar.gz: 1e1471975590f0ad7759e01f85b48f1a6a3aefbe8ea839600565c39c60f5e3a67c0e41d84d6d6d350f8611f179e54027c6bc2b93ee86e27e4e24589f7ecfd3a4
data/lib/nblog_zon.rb CHANGED
@@ -748,58 +748,182 @@ class Naver
748
748
  path = URI.decode_www_form(path)[0][0]
749
749
  if option['라이브러리사용안함'] == 'true'
750
750
  # 현재 탭의 URL을 가져오기
751
-
751
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
752
752
  posting_url = @driver.current_url
753
753
  @driver.execute_script("window.open('#{posting_url}');")
754
754
  sleep(1)
755
755
  @driver.switch_to.window(@driver.window_handles[1])
756
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
757
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
758
- @driver.switch_to.frame(iframe)
759
756
  begin
760
- wait = Selenium::WebDriver::Wait.new(:timeout => 7)
761
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
762
- @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
757
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
758
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
759
+ @driver.switch_to.frame(iframe)
760
+ begin
761
+ wait = Selenium::WebDriver::Wait.new(:timeout => 7)
762
+ wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
763
+ @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
764
+ sleep(1)
765
+ rescue
766
+ end
767
+ @driver.execute_script(<<~JS)
768
+ window.URL.createObjectURL = function() {};
769
+ HTMLInputElement.prototype.click = function() {
770
+ console.log("File dialog suppressed");
771
+ };
772
+ JS
763
773
  sleep(1)
764
- rescue
765
- end
766
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
767
- sleep(1)
768
- Clipboard.copy(path.split('/').join("\\"))
769
- key_down('ctrl')
770
- key_stroke('v')
771
- key_up('ctrl')
772
- sleep(1)
773
- key_stroke('enter')
774
- sleep(2)
775
- @driver.action.send_keys(:up).perform
776
- sleep(1)
777
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
778
- sleep(1)
779
- @driver.switch_to.default_content()
780
- @driver.close
781
- sleep(1)
782
- @driver.switch_to.window(@driver.window_handles[0])
783
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
784
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
785
- @driver.switch_to.frame(iframe)
786
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
787
- key_down('ctrl')
788
- key_stroke('v')
789
- key_up('ctrl')
790
- sleep(1)
774
+
775
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
776
+ # 요소가 나타날 때까지 기다립니다.
777
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
778
+ # 해당 버튼을 찾고 클릭
779
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
780
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
781
+ sleep(1)
782
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
783
+ sleep(1)
784
+
785
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
786
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
787
+ sleep(1)
788
+ # 파일 입력 필드 찾기 (input[type="file"])
789
+ file_input = @driver.find_element(:id, 'hidden-file')
790
+ sleep(1)
791
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
792
+ file_input.send_keys(file_path)
793
+ sleep(3)
794
+ @driver.action.key_down(:up).key_up(:up).perform
795
+ sleep(1)
796
+
797
+ begin
798
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
799
+ #요소가 나타날 때까지 60초 동안 기다립니다.
800
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
801
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
802
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
803
+ sleep(1)
804
+ aria_expanded = element.attribute('aria-expanded')
805
+ if aria_expanded == 'false'
806
+ element.click
807
+ sleep(1) # 클릭 후 잠시 대기
808
+ else
809
+ end
810
+
811
+ begin
812
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
813
+ #요소가 나타날 때까지 60초 동안 기다립니다.
814
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
815
+ sleep(1)
816
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
817
+ sleep(1)
818
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
819
+ sleep(1)
820
+ rescue
821
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
822
+ #요소가 나타날 때까지 60초 동안 기다립니다.
823
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
824
+ sleep(1)
825
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
826
+ sleep(1)
827
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
828
+ sleep(1)
829
+ end
830
+ rescue
831
+ @driver.action.key_down(:down).key_up(:down).perform
832
+ end
833
+ sleep(2)
834
+ @driver.action.send_keys(:up).perform
835
+ sleep(1)
836
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
837
+ sleep(1)
838
+ @driver.switch_to.default_content()
839
+ @driver.close
840
+ sleep(1)
841
+ @driver.switch_to.window(@driver.window_handles[0])
842
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
843
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
844
+ @driver.switch_to.frame(iframe)
845
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
846
+ sleep(1)
847
+ rescue => e
848
+ @driver.quit
849
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
850
+ return 0
851
+ end
791
852
 
792
853
  else
793
- #@driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
794
- @driver.action.key_down(:control).key_down(:alt).send_keys('i').key_up(:alt).key_up(:control).perform
795
- sleep(2)
796
- Clipboard.copy(path.split('/').join("\\"))
797
- key_down('ctrl')
798
- key_stroke('v')
799
- key_up('ctrl')
854
+ @driver.execute_script(<<~JS)
855
+ window.URL.createObjectURL = function() {};
856
+ HTMLInputElement.prototype.click = function() {
857
+ console.log("File dialog suppressed");
858
+ };
859
+ JS
800
860
  sleep(1)
801
- key_stroke('enter')
802
- sleep(2)
861
+ begin
862
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
863
+ # 요소가 나타날 때까지 기다립니다.
864
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
865
+ # 해당 버튼을 찾고 클릭
866
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
867
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
868
+ sleep(1)
869
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
870
+ sleep(1)
871
+
872
+
873
+ # 파일 경로 변환 (슬래시 -> 백슬래시)
874
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
875
+ sleep(1)
876
+ # 파일 입력 필드 찾기 (input[type="file"])
877
+ file_input = @driver.find_element(:id, 'hidden-file')
878
+ sleep(1)
879
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
880
+ file_input.send_keys(file_path)
881
+ sleep(3)
882
+ @driver.action.key_down(:up).key_up(:up).perform
883
+ sleep(1)
884
+
885
+ begin
886
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
887
+ #요소가 나타날 때까지 60초 동안 기다립니다.
888
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]') }
889
+ element = @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//button[@data-name="image-resizing"]')
890
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", element) # 크롤 이동
891
+ sleep(1)
892
+ aria_expanded = element.attribute('aria-expanded')
893
+ if aria_expanded == 'false'
894
+ element.click
895
+ sleep(1) # 클릭 후 잠시 대기
896
+ else
897
+ end
898
+
899
+ begin
900
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
901
+ #요소가 나타날 때까지 60초 동안 기다립니다.
902
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]') }
903
+ sleep(1)
904
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]').click
905
+ sleep(1)
906
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
907
+ sleep(1)
908
+ rescue
909
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
910
+ #요소가 나타날 때까지 60초 동안 기다립니다.
911
+ wait.until { @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]') }
912
+ sleep(1)
913
+ @driver.find_element(:xpath, '//li[@class="se-toolbar-item se-toolbar-item-resizing"]//div[@class="se-custom-layer-option se-custom-layer-option-resizing"]//div[@class="se-custom-layer-resizing-option-group"]//button[@class="se-custom-layer-resizing-reset-button"]//span[@class="se-custom-layer-resizing-reset-label" and text()="초기화"]').click
914
+ sleep(1)
915
+ @driver.action.key_down(:enter).key_up(:enter).perform #엔터
916
+ sleep(1)
917
+ end
918
+ rescue
919
+ @driver.action.key_down(:down).key_up(:down).perform
920
+ end
921
+ rescue => e
922
+ @driver.close
923
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
924
+ return 0
925
+ end
926
+
803
927
  end
804
928
 
805
929
 
@@ -831,217 +955,217 @@ class Naver
831
955
  sleep(1)
832
956
  end
833
957
 
834
-
835
- # end
836
- # components_value['src'] = 'https://blogfiles.pstatic.net'+image_data['item']['url']+'?type=w1'
837
- # components_value['internalResource'] = true
838
- # components_value['represent'] = true
839
- # components_value['path'] = image_data['item']['url']
840
- # components_value['domain'] = "https://blogfiles.pstatic.net"
841
- # components_value['fileSize'] = image_data['item']['fileSize'].to_i
842
- # components_value['width'] = image_data['item']['width'].to_i
843
- # components_value['widthPercentage'] = 0
844
- # components_value['height'] = image_data['item']['height'].to_i
845
- # components_value['fileName'] = image_data['item']['fileName'].to_i
846
- # components_value['caption'] = nil
847
- # if i2.to_s.split('href="')[1] != nil
848
- # components_value['link'] = CGI.unescape(i2.to_s.split('href="')[1].split('"')[0])
849
- # end
850
- # components_value['format'] = 'normal'
851
- # components_value['displayFormat'] = 'normal'
852
- # components_value['imageLoaded'] = true
853
- # components_value['contentMode'] = 'fit'
854
- # components_value['origin'] = {
855
- # 'srcFrom' => 'local',
856
- # '@ctype' => 'imageOrigin'
857
- # }
858
- # components_value['@ctype'] = 'image'
958
+
859
959
  elsif i2.to_s.include?('<video')
860
960
  path = i2.to_s.split('src="')[1].split('"')[0]
861
961
  path = URI.decode_www_form(path)[0][0]
962
+ begin
963
+ @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
964
+ sleep(3)
965
+
966
+
967
+ @driver.execute_script(<<~JS)
968
+ window.URL.createObjectURL = function() {};
969
+ HTMLInputElement.prototype.click = function() {
970
+ console.log("File dialog suppressed");
971
+ };
972
+ JS
973
+ sleep(1)
974
+ # 파일 업로드 버튼 클릭 (이제 파일 선택 창이 뜨지 않음)
975
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
976
+ sleep(3)
977
+
978
+ file_path = path.split('/').join("\\") # 윈도우 스타일 경로로 변환
979
+ sleep(1)
980
+ # 파일 입력 필드 찾기 (input[type="file"])
981
+ file_input = @driver.find_element(:id, "hidden-input")
982
+ sleep(1)
983
+ # send_keys로 파일 경로를 직접 입력하여 파일 업로드
984
+ file_input.send_keys(file_path)
985
+ sleep(3)
986
+
987
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
988
+ sleep(1)
989
+
990
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_description"]').send_keys(title)
991
+ sleep(1)
992
+
993
+
994
+
995
+
996
+ tags2 = option['tag'].to_s
997
+ tag_mm2 = Array.new
998
+ tags2.split(',').each do |tag_value|
999
+ tag_mm2 << ''+tag_value
1000
+ end
1001
+
1002
+ @driver.find_element(:xpath, '//*[@id="nvu_inp_box_tag"]').send_keys(tag_mm2.join("\n")+"\n")
1003
+ sleep(1)
1004
+
862
1005
 
863
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[3]/button').click
864
- sleep(3)
865
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/fieldset/div[1]/button[1]').click
866
- sleep(3)
867
-
868
- Clipboard.copy(path.split('/').join("\\"))
869
- key_down('ctrl')
870
- key_stroke('v')
871
- key_up('ctrl')
872
- sleep(3)
873
- key_stroke('enter')
874
- sleep(3)
875
-
876
- for n in 1..10
877
- puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
878
- if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
879
- break
1006
+ for n in 1..10
1007
+ begin
1008
+ puts @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text
1009
+ if @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[2]/div[1]/ul/li/div/button[1]/div[2]/em').text == '업로드 완료'
1010
+ break
1011
+ end
1012
+ sleep(10)
1013
+ rescue
1014
+ end
880
1015
  end
881
- sleep(10)
1016
+
1017
+
1018
+ @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
1019
+ sleep(3)
1020
+ rescue => e
1021
+ @driver.close
1022
+ puts '동영상 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1023
+ return 0
882
1024
  end
883
- @driver.find_element(:xpath, '//*[@id="nvu_inp_box_title"]').send_keys(title)
884
- sleep(5)
885
- @driver.find_element(:xpath, '//*[@id="video-uploader-wrap"]/div/div/div[3]/button/span').click
886
- sleep(3)
887
-
888
1025
 
889
1026
  elsif i2.to_s.include?('<slide')
890
1027
  if option['라이브러리사용안함'] == 'true'
891
-
1028
+ puts '라이브러리에서 제외되도록 작업을 실행합니다(새로운 창을 생성합니다)'
892
1029
  posting_url = @driver.current_url
893
1030
  @driver.execute_script("window.open('#{posting_url}');")
894
1031
  sleep(1)
895
- @driver.switch_to.window(@driver.window_handles[1])
896
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
897
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
898
- @driver.switch_to.frame(iframe)
1032
+
899
1033
  begin
1034
+ @driver.switch_to.window(@driver.window_handles[1])
1035
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1036
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1037
+ @driver.switch_to.frame(iframe)
1038
+
1039
+
900
1040
  wait = Selenium::WebDriver::Wait.new(:timeout => 7)
901
1041
  wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]') }
902
1042
  @driver.find_element(:xpath, '//*[@class="se-popup-button-text"]').click
903
1043
  sleep(1)
904
- rescue
905
- end
906
-
907
- slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
908
- paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
1044
+
909
1045
 
910
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
911
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
1046
+ @driver.execute_script(<<~JS)
1047
+ window.URL.createObjectURL = function() {};
1048
+ HTMLInputElement.prototype.click = function() {
1049
+ console.log("File dialog suppressed");
1050
+ };
1051
+ JS
1052
+ sleep(1)
1053
+ # 기다릴 시간 설정
912
1054
 
913
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
914
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
915
- # 3. 전체 경로를 클립보드에 복사
916
- Clipboard.copy(paths_with_quotes)
1055
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1056
+ # 요소가 나타날 때까지 기다립니다.
1057
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1058
+ # 해당 버튼을 찾고 클릭
1059
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1060
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1061
+ sleep(1)
1062
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1063
+ sleep(2)
1064
+
1065
+ slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
917
1066
 
918
- # 4. 전체 경로를 붙여넣기
919
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
920
- sleep(1)
921
-
922
- key_down('ctrl')
923
- key_stroke('v')
924
- key_up('ctrl')
925
- sleep(1)
926
- key_stroke('enter')
927
- sleep(2)
928
- #@driver.action.key_down(:control).send_keys('z').key_up(:control).perform
929
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1067
+ # 1. 큰따옴표로 감싸진 경로 추출
1068
+ paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
930
1069
 
931
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
932
- Clipboard.copy(image_names)
933
-
934
- # 8. 이미지 이름만 클립보드에 복사 붙여넣기
935
- @driver.find_element(:xpath, '//*[@class="se-toolbar-item se-toolbar-item-image"]').click
936
- sleep(1)
937
- sleep(1)
938
- key_down('ctrl')
939
- key_stroke('v')
940
- key_up('ctrl')
941
- sleep(1)
942
- key_stroke('enter')
943
- sleep(2)
944
-
945
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
946
- wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
947
- @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
948
- sleep(1)
949
- @driver.action.send_keys(:up).perform
950
- sleep(1)
951
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
952
- wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
953
- @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
954
- sleep(1)
1070
+ # 2. 경로를 윈도우 형식으로 변경
1071
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1072
+
1073
+ # 3. 여러 경로를 번에 전달할 수 있도록 줄바꿈으로 구분
1074
+ file_input = @driver.find_element(:id, 'hidden-file')
1075
+ sleep(1)
1076
+
1077
+ # 여러 파일 경로를 한 줄로 이어서 전달
1078
+ file_input.send_keys(image_paths.join("\n"))
1079
+ sleep(3)
1080
+
1081
+
955
1082
 
1083
+
1084
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1085
+ wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1086
+ @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1087
+ sleep(1)
1088
+ @driver.action.send_keys(:up).perform
1089
+ sleep(1)
1090
+
956
1091
 
957
- @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
958
- @driver.switch_to.default_content()
959
- @driver.close
960
- sleep(1)
961
- @driver.switch_to.window(@driver.window_handles[0])
962
- wait = Selenium::WebDriver::Wait.new(timeout: 10)
963
- iframe = wait.until { @driver.find_element(id: 'mainFrame') }
964
- @driver.switch_to.frame(iframe)
965
- #@driver.action.key_down(:control).send_keys('v').key_up(:control).perform
966
- key_down('ctrl')
967
- key_stroke('v')
968
- key_up('ctrl')
969
- sleep(1)
1092
+
1093
+ wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1094
+ wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1095
+ @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1096
+ sleep(1)
1097
+
1098
+ @driver.action.key_down(:control).send_keys('c').key_up(:control).perform
1099
+ @driver.switch_to.default_content()
1100
+ @driver.close
1101
+ sleep(1)
1102
+ @driver.switch_to.window(@driver.window_handles[0])
1103
+ wait = Selenium::WebDriver::Wait.new(timeout: 10)
1104
+ iframe = wait.until { @driver.find_element(id: 'mainFrame') }
1105
+ @driver.switch_to.frame(iframe)
1106
+ @driver.action.key_down(:control).send_keys('v').key_up(:control).perform
1107
+ rescue => e
1108
+ @driver.quit
1109
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1110
+ return 0
1111
+ end
1112
+
970
1113
 
971
1114
  else
972
-
1115
+ @driver.execute_script(<<~JS)
1116
+ window.URL.createObjectURL = function() {};
1117
+ HTMLInputElement.prototype.click = function() {
1118
+ console.log("File dialog suppressed");
1119
+ };
1120
+ JS
1121
+ sleep(1)
1122
+ begin
1123
+ # 기다릴 시간 설정
1124
+ wait = Selenium::WebDriver::Wait.new(:timeout => 3)
1125
+ # 요소가 나타날 때까지 기다립니다.
1126
+ wait.until { @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]') }
1127
+ # 해당 버튼을 찾고 클릭
1128
+ image_button = @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]')
1129
+ @driver.execute_script("arguments[0].scrollIntoView({block: 'center', inline: 'center'})", image_button) # 크롤 이동
1130
+ sleep(1)
1131
+ @driver.find_element(:xpath, '//ul[@class="se-toolbar se-document-toolbar"]//li[@class="se-toolbar-item se-toolbar-item-image"]//button[@data-name="image"]').click
1132
+ sleep(2)
1133
+
973
1134
  slide_content = i2.to_s.split('<slide>').last.split('</slide>').first.strip
1135
+
1136
+ # 1. 큰따옴표로 감싸진 경로 추출
974
1137
  paths = slide_content.scan(/"([^"]+)"/).flatten # 큰따옴표로 감싸진 경로만 추출
975
-
976
- # 2. 전체 경로를 추출하여 윈도우 경로로 변환
977
- full_paths = paths.map { |path| path.strip.gsub('/', '\\') } # 윈도우 경로 구분자로 변경
978
-
979
- paths_with_quotes = full_paths.map { |path| "\"#{path}\"" }.join(' ')
980
- image_names = paths.map { |path| File.basename(path) }.map { |name| "\"#{name}\"" }.join(' ') # 큰따옴표로 감싼 파일 이름만 추출
981
- # 3. 전체 경로를 클립보드에 복사
982
- Clipboard.copy(paths_with_quotes)
983
1138
 
984
- # 4. 전체 경로를 붙여넣기
985
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
986
- sleep(1)
987
-
988
- key_down('ctrl')
989
- key_stroke('v')
990
- key_up('ctrl')
1139
+ # 2. 경로를 윈도우 형식으로 변경
1140
+ image_paths = paths.map { |path| path.strip.gsub('/', '\\') }
1141
+
1142
+ # 3. 여러 경로를 한 번에 전달할 수 있도록 줄바꿈으로 구분
1143
+ file_input = @driver.find_element(:id, 'hidden-file')
991
1144
  sleep(1)
992
- key_stroke('enter')
993
- sleep(2)
994
-
995
- wait = Selenium::WebDriver::Wait.new(:timeout => 10)
996
- wait.until { @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]') }
997
- @driver.find_element(:xpath, '//*[@class="se-popup-close-button"]').click
1145
+
1146
+ # 여러 파일 경로를 한 줄로 이어서 전달
1147
+ file_input.send_keys(image_paths.join("\n"))
1148
+ sleep(3)
998
1149
 
999
-
1000
- # 6. 이미지 이름만 클립보드에 복사 (큰따옴표 포함)
1001
- Clipboard.copy(image_names)
1002
-
1003
- # 8. 이미지 이름만 클립보드에 복사 후 붙여넣기
1004
- @driver.find_element(:xpath, '//*[@id="'+page_id+'"]/div[1]/div/header/div[1]/ul/li[1]/button').click
1005
- sleep(1)
1006
- sleep(1)
1007
- key_down('ctrl')
1008
- key_stroke('v')
1009
- key_up('ctrl')
1010
- sleep(1)
1011
- key_stroke('enter')
1012
- sleep(2)
1013
-
1014
1150
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1015
1151
  wait.until { @driver.find_element(:xpath, '//*[@for="image-type-slide"]') }
1016
1152
  @driver.find_element(:xpath, '//*[@for="image-type-slide"]').click
1017
1153
  sleep(1)
1018
1154
  @driver.action.send_keys(:up).perform
1019
1155
  sleep(1)
1020
-
1156
+
1021
1157
  wait = Selenium::WebDriver::Wait.new(:timeout => 10)
1022
1158
  wait.until { @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]') }
1023
1159
  @driver.find_element(:xpath, '//*[@data-log="ct.arrfit"]').click
1024
1160
  sleep(1)
1025
1161
  @driver.action.key_down(:enter).key_up(:enter).perform
1026
-
1027
-
1028
- end
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1041
-
1042
-
1043
-
1044
-
1162
+ rescue => e
1163
+ @driver.close
1164
+ puts '이미지 등록실패! 인터넷 접속 불량 및 로딩 지연 다음 작업을 실행합니다.'
1165
+ return 0
1166
+ end
1167
+
1168
+ end
1045
1169
 
1046
1170
 
1047
1171
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nblog_zon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.53
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-24 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: File to Clipboard gem
14
14
  email: rnjstnswp123@naver.com